Cover of Design Patterns

Design Patterns

Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides

3 ideas

  1. Favor Composition Over Class Inheritance

    Inheritance binds subclasses to their parent's implementation at compile time, exposing internals and making changes ripple through the hierarchy. Composing objects from interfaces keeps each piece encapsulated and swappable at runtime, so behavior can be assembled and reconfigured without rewriting class trees.

  2. Observer Pattern Decouples State From Reaction

    An object maintaining state notifies a list of registered dependents whenever it changes, without knowing who they are or what they do. This lets you add or remove reacting components freely, since the subject only broadcasts updates and never references concrete observers.

  3. Program To An Interface Not Implementation

    Client code should depend only on an abstract type that declares what operations exist, never on the concrete class that performs them. This means any object satisfying the interface can be substituted, so dependencies are defined by capability rather than by specific implementation.

Save and mark ideas in the app