Advanced OOP1
Advanced OOP1
Composition
By: Francisco B. Bacamante Jr., DIT
• Objective: Understand the differences, advantages, and use
cases of composition and inheritance in software design.
Inheritance:
• Used in the Template Method Pattern where a base class
defines the structure and subclasses implement specific
behaviors.
Composition:
• Used in the Strategy Pattern, where different behaviors are
encapsulated in separate classes and can be dynamically
assigned.
Case Study
Inheritance:
• Pros: Simple, intuitive, reduces code duplication.Cons: Can lead to
tight coupling, less adaptable to change.
Composition:
• Pros: Flexible, modular, encourages code reuse.Cons: More initial
setup, can add complexity.
Answer the following questions:
1) Explain the main differences between inheritance and composition in OOP. What are the
implications of using one over the other in terms of code flexibility and maintainability?
2) Discuss a scenario where using inheritance can lead to code rigidity and potential issues in
future modifications. How could composition be used as an alternative solution
3) Analyze the impact of inheritance and composition on code reusability and scalability. Which
approach is more advantageous in developing large-scale software systems and why