i have a question..
what the advantages/disadvantages of using classes through inheritance or through composition?
Raz
i have a question..
what the advantages/disadvantages of using classes through inheritance or through composition?
Raz
Advantages/Disadvantages do not really apply when comparing inheritance and composition. You use one or the other based on the type of relationship. Inheritance is an "is a" relationship and composition is a "has a" relationship.
For instance, let's say you have a dog class and want to know if a poodle class should inherit or use the dog class through composition. Well, a poodle "is a" dog so you know you should inherit. But what about using a tongue class? Is a poodle a tongue (some may agree)? No, but a poodle "has a" tongue and therefore the poodle class should contain a tongue reference as a member of the class.
This is the key to keep in mind when trying to choose between inheritance and composition.
David
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them
In the Land of Mordor where the Shadows lie.