Skip to content

Instantly share code, notes, and snippets.

@VictorHom
Last active January 19, 2016 05:17
Show Gist options
  • Save VictorHom/3bd84cb72d58e03d9d78 to your computer and use it in GitHub Desktop.
Save VictorHom/3bd84cb72d58e03d9d78 to your computer and use it in GitHub Desktop.
// Design Pattern by Victor Hom
// Design Pattern - A reusable solution that can be applied to commonly occurring problems in software design.
// 3 main benefits
// 1. Patterns are solutions to problems. There is a degree of certainty that they work since they have been used widely over time
// 2. Patterns can be reused and can be easily adapted to different scenarios. It provides DRYness and you don't have to worry about
// compromising usability.
// 3. Patterns are expressive and offer a common vocabulary among technologists
// Patterns are not a solution. It is a plan/ template that describes how pieces interact to solve certain problems
// There are tradeoffs when you decide to do things one way over another ( there are 'consequences')
// Gang of 4 book is a book that comes to mind when you think of an iconic text about design patterns
/**
Creational Patterns: provide ways to instantiate single objects or groups of related object.
5 such patterns :
Abstract Factory - the abstract factory pattern is used to provide a client with a set of related or dependent objects. The family of objects created by the factory are determined at run-time.
Builder - create complex objects with constituent parts that must be created in the same order or using a specific algorithm. An external class controls the construction algorithm.
Factory - the factory pattern is used to replace class constructors, abstracting the process of object generation so that the type of the object instantiated can be determined at run-tim
Prototype - instantiate a new object by copying all of the properties of an existing object, crating an independent clone. Thie practice is particularly useful when the construction of a new object is inefficient.
Singleton - the singleton patterns ensure that only one object of a particular class is ever created. all further references to objects of the singleton class refer to the same underlying instance (this would be cool to show in javascript)
Structural Patterns: provide a way to define relationships between classes or objects
Adapter : The adapter pattern is used to provide a link between 2 otherwise incompatible types by wrapping the adaptee with a class that supports the interface required by the client
Bridge pattern : The bridge pattern is used to separate the abstract elements of a class from the implementation details, providing the means to replace the implementation details without modifying the abstraction
Composite : The composition patterns is used to create hierarchical , recursive tree structures of related objects where any element of the structure may be accessed and utilized in a standard manner.
Decorator : to extend or alter the functionality of objects at run-time by wrapping them in an object of a decorator class. This provides a flexible alternative to using inheritance to modify behavior
Facade : the faced pattern is used to define a simplified interface to a more complex subsystem
Flyweight : The flyweight pattern is used to reduce memory and resource usage for complex models containing many, hundreds, thousands of similar objects
Proxy : provide a surrogate/ placeholder object, which references an underlying object. The proxy provides the same interface as the underlying subject class, adding a level of indirection by accepting requests from a client obj and passing these to the real subject object as necessary.
Behaviorial Patterns : define manners of communication between classes and objects.
Chain of Responsibility : The chain of responsibility pattern is used to process varied requests, each of which may be dealt with by a different handler
Command : The command pattern is used to express a requests, including the call to be made and all of its required parameters, in a command object. The command may then be executed immediately or held for later use.
Interpreter : is used to define the grammar for instructions that form part of a language or notation, whilst allowing the grammar to be easily extended.
Iterator : The iterator pattern is used to provide a standard interface interface for traversing a collection of items in an aggregate object withou the need to understand its underlying structure.
Mediator : The mediator pattern is used to reduce the coupling between classes that communicate with each other. Instead of classes communication directly, and thus requiring knowledge of their implementation, the classes send messages via a mediator object.
Memento : The memento pattern is used to capture the current state of an object and store it in such a manner that it can be restored at a later time without breaking the rules of encapsulation.
Observer : the observer pattern is used to allow an object to publish changes to its state. Other objects subscribe to be immediately notified of any changes.
State : the state pattern is used to alter the behavior of an object as its internal state changes,. The pattern allows the class for an object to apparently change at run-time.
Strategy : The strategy pattern is used to create an interchangeable family of algorithms from which the required process is chosen at run-time.
template method : define the basic steps of an algorithm and allow the implementation of the individual steps to be changed.
visitor : is used to separate a relatively complex set of structured data classes from the functionality that many be performed upon the data that they hold.
// Design Patterns usually follow these 3 types
// 1. Creational - focuses on object creation and how it can be easier to make objects in different situations.
// 2. Structural - deals with composition of objects.
// 3. Behaviorial - focus on how objects communicate with each other.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment