Abstract Inheritance
12 December 2024 00:12
Why do we prefer code reuse via composition over inheritance?
Advantage using inheritance:
that it is done statically at compile time and easy to use
Disadvantage using inheritance:
it is a static implementation inherited from a parent class and cannot be changed at runtime
Subclass become dependent on parent class this makes harder to reuse the subclass
Code reuse via composition(Object Composition)
Functionality is acquired dynamically at runtime by object collecting reference to other object
Advantage:
is that implementation can be replaced during runtime
Therefore whenever possible use object composition over inheritance
New Section 1 Page 1