Simulating multiple inheritance

Consider a DB schema as follows


Animal
AnimalID
Name

Mammal
AnimalID
HairColour

Fish
AnimalID
ScalesKind

Walker
AnimalID
LegCount

Swimmer
AnimalID
MaxDepth

These tables are all able to be joined to one another via their AnimalID. For example a Shark is represented as:

Animal
AnimalID = 1
Name = Shark

Fish
AnimalID = 1
ScalesKind = Placoid

Swimmer
AnimalID = 1
MaxDepth = 2000

A monkey is represented as

Animal
AnimalID = 2
Name = Monkey

Mammal
AnimalID = 2
HairColour = Brown

Walker
AnimalID = 2
LegCount = 2

While a swimming mammal such as Dolphin is represented as

Animal
AnimalID = 3
Name = Dolphin

Mammal
AnimalID = 3
HairColour = Bald

Swimmer
AnimalID = 3
MaxDepth = 300

If Delphi supported multiple inheritance I would implement a class hierarchy something like this



In my example since TSwimmer and TWalker represent behaviours you may be tempted to say they're better suited to being interfaces e.g. ISwimmer and IWalker, and I would agree that for this specific example they are. This is just a simplified example however and in the real application using interfaces is not as appropriate.

So I'm investigating whether I can write an Aurelius application against a schema such as the one I've described above. My idea was an Aurelius class structure as follows:



The most obvious potential issue is that the Swimmer table is mapped to both TSwimmingMammal and TSwimmingFish. Will Aurelius allow multiple classes to be mapped to the same table? 

Assuming it does, what will happen if I ask for a list of TSwimmingMammals? Will I get just the Dolphin or will it also return the Shark? Any other gotchas?

Thanks very much,

Lachlan

That is not possible and the reason is related to your last question. Aurelius does support polymorphism, which makes it really object-oriented. So for example, if you ask for a list of all TAnimal entities, you will get that. But that is only possible if TSwimmingMammal and TSwimmingFish are saved in different tables. 

Btw, as a small advice (or maybe a question to your approach), since you are considering an ORM, I'd suggest that you give your model an object/class view, instead of table/persistence view. If you were going to model that, indeed it looks more like interface usage. But if that's not the case, how would you model it? Are interfaces not appropriated just because of the persistence layer, or the model itself?

Aurelius doesn't support interfaces anyway, but have you considered using composition instead, so both of your mammal and fish classes contain a composition object of type TBehavior, or even TSwimmer?
OK so asking for a list of all TAnimals won't work. In my application I could probably live with that.

What about my original question, what will happen if I ask for a list of TSwimmingMammals? Will I get just the Dolphin or will it also return the Shark?

Composition is where I was heading if the configuration above was unworkable.

Asking for TSwimmingMammal (or TSwimmingFish) objets will bring both Dolphin and Shark, unfortunately, because they are in the same table.