inheritance

Fluent NHibernate AutoMapping with discriminator

I'm trying to map inheritance with discriminator, but subclasses don't have discriminator value. How to solve it using AutoMappings? Domain objects are as following: public abstract class Item : GuidIdentityEntity { public virtual string Name { get; set; } } public class Product : Item {} public class RawMaterial : Item {} Config...

.NET XML Serialization and inheritance

I have structure like this: public interface A { public void method(); } public class B : A { } public class C : A { } List<A> list; List contains objects of type B and C they also have some fields that I would like to keep, can I now serialize it, deserialize back and get the proper object instances? Preferably to XML EDIT: ...

Refactoring ActiveRecord models with a base class versus a base module

Class A and B are identical: class A < ActiveRecord::Base def foo puts "foo" end end class B < ActiveRecord::Base def foo puts "foo" end end What's the difference between refactoring like this with a base class: class Base < ActiveRecord::Base def foo puts "foo" end end class A < Base end class B < Base end versus li...

Why can't you cast from IList<IParent> to IList<IChild> where IChild implements IParent

Possible Duplicate: IList<Type> to IList<BaseType> I am programming in C# using .NET 2.0 and I don't understand why the cast below results in a null reference. If you have an IList<IChild>, why can't you cast it to an IList<IParent> where IChild implements IParent. using System.Collections.Generic; namespace InterfaceTest { ...

WCF DataContract with an abstract DataMember array

I can't make this scenario work. Here's the pattern- [DataContract] /*abstract*/ class BaseT { ... } [DataContract] class ChildT : BaseT { ... } [DataContract] class MessageContents { [DataMember] public BaseT[] XX; // Array of BaseT objects. I need WCF to somehow figure out that they're actually ChildT. } // ...receive a web...

Nested class forward declaration for template inheritance

What's the proper way to inherit from a template class with the template argument being a nested class within the inheriting class? class SomeClass : public TemplateClass<NestedClass> { class NestedClass {}; }; ...

Making a multi-table inheritance design generic in Django

First of all, some links to pages I've used for reference: A SO question, and the Django docs on generic relations and multi-table inheritance. So far, I have a multi-table inheritance design set up. Objects (e.g: Car, Dog, Computer) can inherit an Item class. I need to be able to retrieve Items from the DB, get the subclass, and do stu...

Requiring a method to be called in a child class constructor

How do I force the Visual Studio compiler to generate an error when a required method is not being called in the constructor of a child class? Like when you edit the form designer code, the compiler complains when InitializeComponent()isn't the first call in the constructor of a form. Is this even possible in VB.NET? ...

How are VTBLs implemented in Java?

Running this code: class A { public int x; public A() { function(); ...

Groovy on Grails: Abstract Classes in GORM Relationships

Grails GORM does not persist abstract domain classes to the database, causing a break in polymorphic relationships. For example: abstract class User { String email String password static constraints = { email(blank:false, nullable:false,email:true) password(blank:false, password:true) } static hasMany = [membership:GroupMembers...

Ruby: OOP & two-dim array question

I need to create a two-dimensional array Class. I've done a work, but discovered that my class simply has an inner two-dim array, and to access the elements I have to write a redundant word 'table': class Table attr_accessor :table def initialize(w,h) @table = Array.new(h) h.times do @table << Array.new(w) end end x = Ta...

c++ virtual class, subclass and selfreference...

consider this class: class baseController { /* Action handler array*/ std::unordered_map<unsigned int, baseController*> actionControllers; protected: /** * Initialization. Can be optionally implemented. */ virtual void init() { } /** * This must be implemented by subclasses in order to implement...

can one class inherit from an other class an have implemented an interface at same time ?

somthing like public partial class RegistrationForm : IRegistrationForm, System.Web.UI.UserControl but this example does not work. ...

Common way to call mother-class operator= in C++?

Let's suppose I have a class Dog that inherits from class Animal, you might want to insert a call to Animal::operator= in Dog::operator=. What is the most readable/common way to write it? I think I know those two... static_cast<Animal*>(this)->operator=(other); and this->Animal::operator=(other); ...

Determining child interface closest to a class

Lets say I have a inheritance tree of interfaces: IParent > IChild > IGrandChild How would I: Find a class that implements IParent Determine the closest ancestor of the class that is also a child of IParent. For example: var myClass = FindImplementor<IParent>(); var myInterface = ClosestAncestor<IParent, myclass>(); I'm not look...

Interface Inheritance in C++

I have the following class structure: class InterfaceA { virtual void methodA =0; } class ClassA : public InterfaceA { void methodA(); } class InterfaceB : public InterfaceA { virtual void methodB =0; } class ClassAB : public ClassA, public InterfaceB { void methodB(); } Now the following code is not compilable: int...

Extending Flex FileReference class to contain another property

I want to extend the FileReference class of Flex to contain a custom property. I want to do this because AS3 doesn't let me pass arguments to functions through event listeners, which makes me feel sad, so I need this property to exist on the event target, so I can access it. I also want to be able to cast extant FileReference objects to...

How to Inherit method but with different return type?

Given the following classes: ClassA { public ClassA DoSomethingAndReturnNewObject() {} } ClassB : ClassA {} ClassC : ClassA {} Is there a way to get ClassB and ClassC to inherit the method but customize the return type to their own class? I prefer not to copy the method from ClassA and change the type there. I need ...

How to use a method from a class in another class without extending

Sorry if my question sounds weird lol I'll try to explain. I have 4 classes: Karakter, Karakters, Orc, Human. Orc and Human both extend Karakter. Karakters is an ArrayList with Karakter in it. I have a method in both Orc and Human called: public String getRace(). Now I want to use this method in Karakters?!! When I try to do this, it ...

Embedding instead of inheritance in Go

What is your opinion of this design decision? What advantages does it have and what disadvantages? Links: Embedding description ...