Skip to content

🧱 Structural Design Patterns

Structural patterns focus on how objects and classes are composed to form larger structures. They help you build systems that are flexible, maintainable, and easy to extend without changing existing code.


βœ… Why Structural Patterns Matter

  • Improve flexibility by wrapping or adapting existing components.
  • Reduce coupling between parts of the system.
  • Add features without modifying existing classes.

βœ… Common Structural Patterns

1) Adapter

Makes one interface compatible with another.

βœ… Use when: you need to integrate a legacy or third‑party class.

2) Decorator

Adds behavior to objects dynamically by wrapping them.

βœ… Use when: you want optional features without subclass explosion.

3) Facade

Provides a simple interface to a complex system.

βœ… Use when: clients should only see a small, easy entry point.


βœ… Example: Adapter

class LegacyPayment:
    def pay_cents(self, cents):
        print(f"Paid {cents} cents")


class PaymentAdapter:
    def __init__(self, legacy_payment):
        self.legacy_payment = legacy_payment

    def pay(self, dollars):
        self.legacy_payment.pay_cents(int(dollars * 100))


gateway = PaymentAdapter(LegacyPayment())
gateway.pay(9.99)

πŸ” Key Takeaways

  • Structural patterns organize how parts fit together.
  • Adapters translate interfaces, decorators extend behavior.
  • Facades simplify complex subsystems.

Next: Behavioral Patterns β†’