Design Patterns
Design Patterns
SOLID Principles
1. Single responsible principle
- One class should have one and only one responsibility
- Example – Suppose we have Employee and Address Class, if we want to change the state of
Employee then we do not need to modify the class Account and vice-versa.
2. Open/Close principle
- Software components should be open for extension, but closed for modification
- Example – “Open for extension” means that we can extend and include extra functionalities in
our code without altering or affecting our existing implementation.
“Closed for modification” means that after we add the extra functionality, we should not modify
the existing implementation.
- Dependency injection is a software design pattern it’s always to develop loosely couple code
- It is help us to reduce tide couple amount the software component
- DI design pattern used to implement IoC (Inversion of control).
- It allows the creation of dependency objects outside of a class and provides those objects to a
class in different ways.
- Tight Coupling
Tight coupling means two objects are dependent on each other. That means when a class is
dependent on another class, then it is said to be a tight coupling between these two classes.
- Loose Coupling
- Loosely coupling means two objects are independent of each other. That means if we change
one object then it will not affect another object.
- when we need to ensures that only one instance of a particular class is going to be created and
then provide simple global access to that instance for the entire application.
- Advantages
- if we are sharing a resource with multiple clients simultaneously, then concurrent access to that
resource is well managed by the singleton design pattern.
- Implementation
- create constructor with private access modifier and parameter less because it is not allows to
create instance of class
- The class should declare sealed which will ensure that it cannot be inherited
DESIGN PATTERN
- You need to create private statis variable to hold reference to single create instance of class.
- You also need to create a public static properties/method which will return the single created
instance of singleton class.
- Thread Safe