Design Patterns
Another useful site: http://www.dofactory.com/Patterns/Patterns.aspx
· Creational - the way classes instantiate
o Singleton 18
§ Ensure a class has one instance
· Hide “New” Constuctor
· Add Shared solitary instance of self
o Abstract Factory 21
§ Create families of related or dependent objects without specifying classes
· Daddy, Mommy, Baby Bear (interfaces)
o Builder n/a
§ Separate the construction of a complex object from its representation so that the same construction process can create different representations
o Factory Method 26
§ Design an Interface for object creation, but let sub-classes decide which class to instantiate.
· Protected member can be inherited
· Overridable methods
o Prototype n/a
§ Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype
· Structural – the way classes inherit
o Adapter 29
§ Convert an interface for a class into another interface clients expect
o Facade 29
§ Provide a unified interface A for sub-interfaces 1, 2, 3
o Bridge 34
§ Decouple an abstraction from an implementation so that the 2 can vary independently
· Purchase Orders Interface
· Suppliers Implementation
o Composite 39
§ Compose objects into a tree structure collection of containers and leaves to represent part-whole hierarchies to let clients treat objects and compositions of objects uniformly.
o Decorator 43
§ Attach additional responsibilities on Objects dynamically
· Interface -> Concrete -> Decorator -> Sub-Decorators
o Proxy 49
§ Provide ObjB surrogate of an ObjA to control (limit/override) access to ObjA.
o Flyweight n/a
§ Provide a shared object/structure for a one-instance, shared data structure
· Behavioral – supervise messages between objects
o Observer 52
§ Define a one way dependency between objects so that when an objects change state, dependents are notified.
· Sender Interface notifies Observer Interface
o State 55
§ Allow object to alter behavior when internal distinguishable state changes.
· Sender Interface notifies Observer Interface
· Example: Lightbulb has a "Press Switch" method which changes the state of a private property.
o Strategy 60
§ Encapsulate each of a family of algorithms so that algorithm varies for client.
· Sender Interface notifies Observer Interface
· Example: Arrange interfaces so that inheriting classes implement a method differently, then code calls one or other inheriting class.
o Visitor n/a
§ change the class structure without changing the actual class to separate the logic and algorithm from the current data structure.