inheritance

Forcing sub classes to implement a method

Hi I am creating an object structure and I want all sub classes of the base to be forced to implement a function. The only ways I could think of doing it were: An abstract class - Would work but the base class has some useful helper functions that get used by some of the sub classes. An interface - If applied to just the base class t...

link_to issue with inherited Active Record class.

Here are the classes as I have them set up: class Stat < ActiveRecord::Base belongs_to :stats_parent end class TotalStat < Stat belongs_to :stats_parent end #The StatsParent class is just to show how I use the relation. class StatsParent < ActiveRecord::Base has_one :total_stat has_many :stats end For the Stats Cont...

How to get the properties of a class using reflection (specifying how many levels of heirarchy) in C#.Net?

So for example: class GrandParent { public int GrandProperty1 { get; set; } public int GrandProperty2 { get; set; } } class Parent : GrandParent { public int ParentProperty1 { get; set; } public int ParentProperty2 { get; set; } protected int ParentPropertyProtected1 { get; set; } } class Child : Parent { publi...

How do I apply the DRY principle to iterators in C++? (iterator, const_iterator, reverse_iterator, const_reverse_iterator)

OK, so I have two (completely unrelated, different project) classes using iterators now. One has iterator and reverse_iterator working as intended, and the other, current one has iterator and a semi-broken const_iterator (specifically, because const_iterator derives from iterator, the code LinkedList<int>::iterator i = const_list.begin()...

C++ collection of abstract base classes

hello how can I create STL collection of classes which implement abstract base class using the base class as collection value, without using pointers? is there something in Boost that allows me to implement it? The collection specifically is map. Thanks ...

In C#, is it possible to cast a List<Child> to List<Parent>?

I want to do something like this: List<Child> childList = new List<Child>(); ... List<Parent> parentList = childList; However, because parentList is a List of Child's ancestor, rather than a direct ancestor, I am unable to do this. Is there workaround (other than adding each element individually)? ...

A question about Generic inheritance

public class Leaf : IComponent<Leaf> { //... } Does this type of generic inheritance mechanism have any specific name? What is the benefit of this type of usage of Generics? ...

C++ Templates vs. Aggregation

Consider the following piece of code: class B { private: // some data members public: friend bool operator==(const B&,const B&); friend ostream& operator<<(ostream&,const B&); // some other methods }; template <typename T=B> class A { private: // some data members vector<vector<T> > vvlist; public: /...

Special interaction between derived objects (i.e. mutiple dispatch)

So, I have a list of base class pointers: list<Base*> stuff; Then, at some point one of the objects will look through all other objects. Base * obj = ...; // A pointer from the 'stuff'-list. for (list<Base*>::iterator it = stuff.begin(); it != stuff.end(); it++) { if (obj == *it) continue; // Problem scenario is here...

How to get a base class method return type to be the subclass type?

I have a copy function that I'd like to override in subclasses to return the type of the subclass. Here are my interfaces: Public Interface IBase(Of T) Function Copy() As T End Interface Public Interface ICar Inherits IBase(Of ICar) End Interface Public Interface IToyota Inherits ICar End Interface And here are my classe...

How to instantiate a descendant UserControl?

Here is the scenario. I have a bunch of UserControls that all inherit from MyBaseControl. I would like to instantiate a UserControl based on its name. For instance: void foo(string NameOfControl) { MyBaseControl ctl = null; ctl = CreateObject(NameOfControl); // I am making stuff up here, ...

Sharing methods between two implementations of a virtual base class in C++

I have a virtual base class and two classes that implement the various methods. The two classes have the same functionality for one of the methods. Is there away I can share the implementation between the two classes to eliminate redundant code? I tried making the first class a parent of the second class in addition to the virtual base c...

C++ inheritance problem

Here are my classes: ParentClass, ParentObj DerivedClass (inherits from ParentClass), DerivedObj (inherits from ParentObj). ParentClass has a protected member: std::vector< ParentObj* > DerivedClass allocates only DerivedObj* objects to this vector. Problem is: When I use ParentClass, I want to access its vector object...

C#: interface inheritance getters/setters

I have a set of interfaces which are used in close conjunction with particular mutable object. Many users of the object only need the ability to read values from the object, and then only a few properties. To avoid namespace pollution (easier intellisense) and to get across the usage intent, I'd like to have a small base interface whic...

Python: dynamic class generation: overwrite members

I have a python class hierarchy, that I want to extend at runtime. Furthermore every class in this hierarchy has a static attribute 'dict', that I want to overwrite in every subclass. Simplyfied it looks like this: 'dict' is a protected (public but with leading underscore) member class A(object): _dict = {} @classmethod de...

Linq Entity Inheritance makes BIG SQL Sentences

We are developing an application with a base entity with more than 10 childs (which inherited from it). When we make any request with Linq to the base entity we get a SQL statement with a "UNION ALL" for each child. To make a Count() over the base entity it takes near one second and getting only one row can takes two seconds. For this ...

Django Multi-Table Inheritance VS Specifying Explicit OneToOne Relationship in Models

Hope all this makes sense :) I'll clarify via comments if necessary. Also, I am experimenting using bold text in this question, and will edit it out if I (or you) find it distracting. With that out of the way... Using django.contrib.auth gives us User and Group, among other useful things that I can't do without (like basic messaging). ...

Any better way to tailor a library than inheritance?

Most likely an OO concept question/situation: I have a library that I use in my program with source files available. I've realized I need to tailor the library to my needs, say I need to modify the behavior of a single functions F in class C, while leaving the original library's source intact, to be able to painlessly upgrade it when ne...

virtual derived class of a non-virtual base class

I have a virtual class that has been derived from a non virtual class. But when I c-style cast the derived class to base class, the class is corrupted. I am looking at the member variables using the debugger and the member variables are all corrupted when I do that cast. I see there is a 4 byte discrepency when I do that cast(may be the ...

can a base class tell what item is inheriting it

I have a base clase "AsyncHandlerBase" public class CameraAlertsQuery : AsyncHandlerBase the base class is inherited by multiple pages. is there any way in the base class to execute specific code when a particular class is inheriting it? I would have that particular code executed on the page itself, but it is not possible in this ca...