Design Patterns
Design Patterns
them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
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.
The Factory Method Pattern: defines an interface for creating an object, but lets
subclasses decide which class to instantiate. Factory Method lets a class defer instantiation
to subclasses.
The Abstract Factory Pattern: provides an interface for creating families of related or
dependent objects without specifying their concrete classes.
The Singleton Pattern: ensures a class has only one instance, and provides a global point
of access to it.
The Adapter Pattern: converts the interface of a class into another interface the clients
expects. Adapter lets classes work together that couldn’t otherwise because of incompatible
interfaces.
Principles
Encapsulate what varies
Favor composition over inheritance
Program to interfaces, not implementation
Strive for loosely coupled designs between objects that interact
Classes should be open for extension, but closed for modification
Depend upon abstractions. Do not depend upon concrete classes