Rather than using a null reference when an object is absent, create an object which implements the expected interface but whose methods have no behavior.
Many of the behavioral design patterns such as State and Strategy allow implementation to vary without specializing clients. Often when a behavior or algorithm has many different versions, one of those versions may be to have no behavior at all. To avoid putting special-case conditional code, “if(!null)” for example, into clients, a Null Object can be used.
Continue reading “The Null Object”
Set up a structure that allows the addition of operations across a variety of classes without changing the classes.
Continue reading “The Visitor”
Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later. (GoF)
Continue reading “The Memento”
Use sharing to support large numbers of fine-grained objects efficiently. (GoF)
Continue reading “The Flyweight”
When a unit being tested has a dependency, replace that dependency with a version that is only for testing, called a Mock Object. The Mock Object can be conditioned and inspected by the test.
Continue reading “The Mock Object”
Separate the construction of a complex object from its representation so the same construction process can create different representations. (GoF)
Continue reading “The Builder”
Ensure a class only has one instance and provide a global point of access to it. (GoF)
Continue reading “The Singleton”
Separate a varying Entity from its varying Behavior, so that the two can vary independently. Another way to state the intent is, the Bridge is one variation using another variation in a varying way.
Continue reading “The Bridge”
We want to handle items that are hierarchically related (either through Classification or like a Bill of Material) as objects.
Continue reading “The Composite”
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. (GoF)
Continue reading “The Chain of Responsibility”