https://github.com/faif/python-patterns
Creational , Ploymorphism
Factory : Uncertain in types of objects, Decisions to be made at runtime regarding what classes to use
Singleton: Only one instance, Global variable in an object-oriented way, An information case, shared by multiple objects
Builder: Director, Abstract Builder : interfaces, Concrete Builder: implements the interfaces, Product : object being built, divide and conquer strategy
Prototype: (Creating many identical objects individually is expensive. Cloning is an alternative) Create a prototypical instance first. Simply clone it whenever you need replica.
Structural, Inheritance
Decorator: New features to an existing object, Dynamic changes, Not using subclassing.
Proxy: Postpone object creation unless absolutely necessary. Find a placeholder.
Adapter: Incompatible interfaces
Composite: Recursive tree structure. Component(abstract class), Child (concrete class), Composite(concrete class)
Bridge: Two unrelated, parallel, or orthogonal abstractions. One is implementation specific. The other is implementation independent.
Behavioral, Methods and their signatures
Observer: establishes a one-to-many relationship between a subject and multiple observers. Subjects to be monitored. Observers to be notified.
Visitor: allows adding new features to an existing class hierarchy without changing it.
Iterator: allows a client to have sequential access to the elements of an aggregate object without exposing its underlying structure.
Strategy: offers a family of interchangeable algorithms to a client. The problem we often see is that there is a need for dynamically changing the behavior of an object.
Chain of responsibility: opens up various possibilities of processing for a given request. Decouples the request and its processing.
Coupling and Cohesion
Coupling: The degree to which your software elements are connected
Cohesion: The degree of independence
The goal of design patterns: More cohesion and less coupling
No comments:
Post a Comment