- Inheritance is used for
- Code resuse
- To support polymorphism
- Disadvantages of inheritance
- Difficult to change the interaface of the subclass
- Superclass is always instantiated
- Can get complex and unmanageable
- Composition is used for code reuse
- Disadvantages of composition
- We cannot use polymorphism
- We cannot extend the system by adding subclasses
- May have a slight performance overhead
- Usage
- Inheritance: IS- A
- Composition: HAS - A
|
Java2html |
Resources:
Note: This post was originally posted on my blog at http://www.adaptivelearningonline.net
Comments