I'm reading a book on general object oriented concepts to try and gain a solid understanding of everything. One thing that is throwing me off is the difference between Inheritance and Composition. I know that in terms of Inheritance, it is "is-a" with the subclass. Such as an Employee class inherits from the Person class, because an employee "is-a" person. Composition's subclass is "has-a". For example, a Car class inherits from the Steering Wheel class because the car "has-a" steering wheel.
Cool, so far. But... isn't this still inheritance? I understand the difference between "is-a" and "has-a". I also understand that Composition is basically combining multiple classes to make another class that contains all of those objects. I have two questions:
- Isn't composition still a form of inheritance in some ways?
- Typing this out, I may have answered my own question. In Objective-C, we use Protocols to specify what needs to be inherited and what is optional. Is simply throwing a protocol into the header what differentiates Inheritance and Subclassing? Do we use protocols in both inheritance and composition?
I understand the difference quite well, and know how to utilize each through my programs. I guess it's just a question regarding semantics, if composition is really a form of inheritance or not.