Design Patterns are solutions to to commonly occurring problems.
We need design patterns to ensure our work is consistent, reliable and understandable.
- Building Architecture
- Electrical and plumbing
- Automobile design
- Mobile phone interfaces
- Creational - Used to design object creation
Examples: Singleton, Factory, Builder
- Structural - Used to design relationship between objects
Examples: Adapter, Facade, Composite
- Behavioural - Used to design object interaction and responsibility
Examples: Command, Observer, Stratergy
- Single Responsibility: Means a Class should have only one responsibility i.e, Cooking or Washing but not both
- Open-Closed: Class should be
open for extension
usually by inheritance butclosed for modification
- Liskov Substitution: Subclasses should stand in for parents without breaking anything
- Interface Segregation: Many specific interfaces are better than one do it all interface (in python we use Abstract Base Class combined with multiple inheritance to achieve this)
- Dependency Inversion: We should program towards
Abstraction
not concreteImplementation
causeImplementation
can vary. In python ABC(Abstract Base Classes) can be used just for this.
Note: About Interfaces in Python
Unlike other languages Python do not have standard way to define interfaces. In Python we can implement Interfaces using ABC(Abstract Base Classes)
-
-
- Also known as
Policy pattern
- Also known as
-
- Also known as
Dependents pattern
,Publish-Subscribe pattern
- Description: When the state of one object changes it's dependents are notified
- Also known as
-
- Also known as
Action pattern
,Transaction pattern
- Also known as
-
-
-
- Also known as
Anti pattern
because of it's downsides
- Also known as
-
-
-
-
- Unified interface to a set of interfaces
-
- Bridging the incompatible APIs
-