is a and has a relationship
- the is-a relationship is expressed with inheritance
- has-a relationship is expressed with composition
- both inheritance and composition allow you to place sub objects inside your new class
- two of the main techniques for code reuse are class inheritance and object composition
- inheritance is uni-directional
- for exam house is a build but building is not a house
- inheritance uses extends keyword
- composition is used when house has a bathroom
- it is incorrect to say house is a bathroom
- composition simply means using instance variable that refer to other objects
- the class house will have an instance variable which refers to bathroom object
- don't use inheritance just to get code reuse if there is no is-a relation then use composition for code reuse
- overuse of implementation inheritance can break all the subclasses, if the superclass is modified
- don't use inheritance just to get polymorphism, if there is no is-a relation and all you want is polymorphism then use interface inheritance with composition, which gives you code reuse