Design Pattern
Overview
- Following best practices to avoid code smell(bad code) we use design patterns.
- Simply knowing a programming language and its constructs will not make you a better programmer or developer. It requires knowledge of Design Patterns to create software that will work today and also in future.
- Each Design Pattern is for solving a particular kind of situation; there might be situations where more than one Design Pattern can be used.
Principles of design pattern/object oriented design patterns
1) Prefer composition over Inheritance
2) Code for interface not for Implememtation
Types of design patterns
- 1) Creational β> If the requirement is to create an object, to get that object we use creational design pattern. Singleton, Factory, Abstract Factory, Builder, Prototype
- 2) Structural β> If we want to compose an object(have one object and want to include other into existing object or one object using other object properties) then we use structural design pattern. Adapter, Composite, Proxy, Fly weight, Facade, Bridge, Decorator
- 3) Behavioural β> If we have 2 objects but donβt want to compose them but we want to make communication between that 2 objects then we use behavioural design pattern. Template method, Mediator, Chain of responsibility, Observe, Strategy, command, state, visitor, Iterator, Interpreter, Memento