Files
org_roam/book-notes/Head First Design Patterns.org
2026-01-03 00:10:12 +00:00

1.8 KiB
Raw Blame History

HFDP

Head First Design Patterns

Chapter 1

Structural:

The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

  • Encapsulate what varies
  • Favor composition over inheritance
  • Program to interfaces, not implementations

Chapter 2

Observer:

The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.

Subjects, or as we also know them, Observables, update Observers using a common interface

Observers are loosely coupled in that the Observable knows nothing about them, other than that they implement the Observer interface.

You can push or pull data from the Observable when using the pattern (pull is considered more “correct”).

Dont depend on a specific order of notification for your Observers.

Java has several implementations of the Observer Pattern, including the general purpose java.util.Observable

  • Strive for loosely coupled designs between objects that interact

Notes for page 137

  • Classes should be open for extension, but closed for modification.

Notes for page 142

Notes for the decaroter pattern.

Notes for page 143

Decorator pattern: The Decorator Pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.