![]() |
|
The best resource for .NET Developers. This blog guides about .NET (C#.NET, ASP.NET, ASP.NET MVC, SQL Server, ADO.NET), AngularJS, JSON, HTML, JavaScript, jQuery, CSS, Bootstrap, DotNetNuke, and .NET interview questions. This blog teaches everything about the .NET. Here you can find bunch of tutorials, Tips and tricks, code samples and examples.
Thursday, 9 July 2020
SOLID Design Principles in C# - Dependency Inversion Principle (DIP)
Tuesday, 7 July 2020
SOLID Design Principles in C# - Interface Segregation Principle (ISP)
![]() |
Definition of the Interface Segregation Principle?
Blog Post Interface
Interface Segregation Principle Implementation
SOLID Design Principles in C# - Open/Closed Principle (OCP)
The open-closed principle definition by Bertrand Meyer
“Software
entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.”
Closed for modification: Once the entities are defined those should not be touched later on.
Once you implemented the base class you should not modify the functionality, if you change it, it will end up changing the behavior of the derived classes. It leads to code changes in all derived classes as well, you will mess up whole derived classes code every time you change the base class. Code maintenance will become difficult, and the code won't be flexible for the further changes.
Open Closed Principle helps in avoid touching the base class and allows the class to extends the functionality of it's by implementing the new class.
Real Life Example:
- An adapter is closed for modification it provides flexibility to use the ports.- So you can use the extension board and use it for different purpose.
- You can charge the mobile, laptop, power banks with the extension cables.
Lets take an example of salary processing in a company which sets the max salary based on the designation.
Class which violates Open/Closed Principle
Open/Closed Principle Implementation
Single Responsibility Principle (SRP)
https://dotnetcookie.blogspot.com/2019/12/solid-design-principles-in-c-single.html
https://dotnetcookie.blogspot.com/2020/07/solid-design-principles-in-c-liskov.html
Interface Segregation Principle (ISP)
https://dotnetcookie.blogspot.com/2020/07/solid-design-principles-in-c-interface.html
https://dotnetcookie.blogspot.com/2020/07/solid-design-principles-in-c-dependency.html