# Design patterns

## Creational designs

* ### Factory method
    
    Abstract class that requires subclasses to implement a function that return abstract object.
    
    Name meaning + example: Factory (abstract method) that create product (abstract object).  
    
* ### Abstract factory
    
    Abstruct class that requires subclasses to implement set of functions that return abstract objects.
    
    Name meaning: factory is a class that contains number of fatroy methods….  
    
* ### Singleton
    
    Can have just one instance from class.
    
    Name meaning + examlpe: singleton == single one.  
    
* ### Builder
    
    Build an object from number of objects \\ in stages (from outside the builded object).
    
    Name meaning + examlpe: builder == build the object, object that build the object in stages from outside.
    

## Structural designs

* ### Adapter
    
    Corelate between two unmatched APIs.
    
    Name meaning + examlpe: adapt between un matched interfaces / APIs…  
    
* ### Proxy
    
    Corelate API to new ProxyAPI with access / security / limitations control.
    
    Name meaning + examlpe: Proxy server is a standalone security/access entity between interfaces….  
    
* ### Façade
    
    Corelate API to new FacadeAPI with simple and useable interface to the user.
    
    Name meaning + examlpe: Facade, close to Decorated, but more fixed and not dynamic.
    
* ### Flyweights
    
    Memory smart managment by sharing memory between objects.
    
    Name meaning + examlpe: light use of memory so flyweight.
    
* ### Composite
    
    Tree like structure that every object can be for himself or as big part that contain objects from same type. Recuratsion types.
    
    Name meaning + examlpe: Object that is composite from same type objects.
    

### Behavioural designs

* ### Mediator
    
    Object that orchestrates between other objects flow.
    
    Name meaning + example: As mediator the job of the object is to mediate and set communication between other objects.
    
* ### Observer
    
    Objects look at other object state in order to function based on its state and flow.
    
    Name meaning + example: As observer, object look at other objects state and flow in order to set its flow.  
    
* ### Strategy
    
    Let you define a set of algorithms.  
    Strategy design pattern implements regular inheritance in order to simplify class that does something specific in a lot of different ways by extract all of these different algorithms into separate classes called *strategies*.  
    The abstract class have one function with desired signature in order to allow generic use of different instance algorithms to the same algorithmic problem.
    
    Name meaning + example: General strategy as a solution for certain problem.  
    Find sorted list problem - the general strategy will get a list and will return a sorted list, there are many maney different strategy implementations.
    
* ### Template method
    
    Like strategy design pattern, the difference is that the main function should be more structured, calling set of stages methods that need to be implemented.
    
* Name meaning + example: Template of method flow. Startup object *run\_startup* method will call *market\_research* method and than *competition\_analysis* and than *solution\_building*.
    
* ### Visitor
    
    Alter different object in order to add functionality from outside of the object.
    
    Name meaning + example: Visit other objects, Dog class shouldn't have method routine test with an injection, in replace we crate a veterinarian visitor class that will visit the dog class ind will implment this method on him…..
