0% found this document useful (0 votes)
3 views

Design Patterns

The document outlines key software design patterns and principles, including the SOLID principles which emphasize single responsibility, open/close, Liskov substitution, interface segregation, and dependency inversion. It discusses dependency injection as a means to achieve loose coupling, as well as the singleton pattern for ensuring a single instance of a class. Additionally, it introduces the factory design pattern for creating objects from subclasses based on provided data.

Uploaded by

Suraj Javarat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Design Patterns

The document outlines key software design patterns and principles, including the SOLID principles which emphasize single responsibility, open/close, Liskov substitution, interface segregation, and dependency inversion. It discusses dependency injection as a means to achieve loose coupling, as well as the singleton pattern for ensuring a single instance of a class. Additionally, it introduces the factory design pattern for creating objects from subclasses based on provided data.

Uploaded by

Suraj Javarat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

 DESIGN PATTERN

 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.

3. Liskov substitution principle


- Child class can be substitute with the parent class object

- Example – use override the keyword into multiple class


 DESIGN PATTERN

4. Interface segregation principle


- Class, interface also should have a single responsibility. That’s means we should not force any
class to implement any method.

5. Dependency inversion principle


- high-level modules/classes should not depend on low-level modules/classes. Both should
depend upon abstractions.

 Dependency Injection Design Pattern

- 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.

- Type of dependency injection


- 1. Constructor, 2. Property, 3. Method

- 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.

 Singleton Design Pattern

- 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

 Factory Design Pattern


- if we have a superclass and n number of subclasses, and based on the data provided, if we have
to create and return the object of one of the subclasses, then we need to use the Factory Design
Pattern in C#.
 DESIGN PATTERN

You might also like