Reputation: 578
I've found a question asking about the differences between class inclusion and class inheritance. What exactly does class inclusion mean? I don't think I've hear this term before ..
Upvotes: 1
Views: 912
Reputation: 3282
Think about your problem in terms of "is-a" and "has-a" (composition and inheritance). Please take a look at: Is-a and Has-a.
In short terms - if the class/object you're trying to implement "is" an instance of something more general, then it is an example of inheritance i.e.: Apple (derived class) is a Fruit (base class), Porsche is a Car etc.
If your object "has" or "is part of" something, then it is composition. Example: Car has an Engine (object of Engine is included in every Car object), House has Windows and Doors etc.
Whether you should use one or another is a topic for a different type of discussion. In general you want to prefer composition over inheritance as this allows for more flexible code.
Upvotes: 2
Reputation: 41
Inclusion may have different treatments depending on the context:
One of the main conceptual differences of all forms of inclusion from inheritance is that inclusion assumes that many elements can be included in one (parent) element at the level of instances. In contrast, the classical inheritance (implicitly) assumes that an object may have only one extension. In other words, a super-object cannot be shared among many extensions.
Note again that it is probably not a complete list and there are significant overlaps between the above treatments as well as some incompatibilities.
Upvotes: 0
Reputation: 9416
It's composition. Generally speaking, prefer composition over inheritance. Use inheritance to model only is-a-relationship (Liskov principle), not uses, dependencies or implemented-in-terms-of.
Upvotes: 2