Common Software Design Patterns
Adapted from: Head First Design Patterns. Please buy the book, it’s quite amazing.
Also check out: Big-O Cheat Sheet
Provides an interface for creating families of related or dependent objects without specifying their concrete classes
Converts interface of a class to another interface that a consumer expects. The consumer would not be able to use the original class otherwise.
Encapsulates a request as an object
Allows composing objects into tree structures, to describe hierarchy. Lets consumers treat individual objects and compositions uniformally.
A flexible way to attach functionality to an object dynamically, without using subclassing.
Provides a higher-level interface that provides simpler way of interacting with a composite system than using the individual interfaces of the components that make up the system.
Interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses
A universal way to access elements of an aggregate object sequentially, regardless of the inner nature or implementation of the aggregate object.
Common approach to complex application design that separates code components into three buckets: Models, Views and Controllers, allowing seperation of business logic from the presentation.
Observer pattern provides a mechanism to establish one-to-many dependency between objects, so that “dependents” can be notified when the “observed” object changes its state.
Proxy (Protection, Remote, Virtual)
A proxy object is a surrogate or a placeholder for another object. Typical use-cases include when access to the “original” object needs to be protected because it is either: requiring security (Protection Proxy), happens over-the-network (Remote) or is otherwise expensive (Virtual).
Ensure that a class has only one instance and provide global pont of access to that instance.
A way for an object to change its behavior based on its internal state. Typically used as a cleaner alternative to long list of conditional statements. Similar in nature to the Strategy pattern.
Provides a way to encapsulate interchangeable algorithms, selecting which algorithm to use at runtime.
defines the skeleton of an algorithm in a method, deferring some steps to subclasses. Subclasses may redefne some steps of the algorithm at runtime, without changing the algorithm structure.