Author - StudySection Post Views - 430 views
SOLID principles

SOLID principles in C# Language

Definition: SOLID principles are the design principles that enable us to manage most of the software design problems. SOLID principles provide us with ways to maneuver from tightly coupled code and tiny encapsulation to the specified results of loosely coupled and encapsulated real needs of a business properly. SOLID is an acronym of the following.

SOLID principles1

S: Single Responsibility Principle (SRP)

The single-responsibility principle (SRP) states that every class, module, or function in your program should only do one job. In other words, each should have full responsibility for one functionality of the program. The class should contain only variables and methods relevant to its functionality.
Classes can work together to finish larger complex tasks, but each class must complete a function from start to end before it passes the output to a different class.
SRP makes it easy to follow another well-respected principle of OOP, encapsulation. It is easy to keep data secret from the user when all data and methods for a feature are within the single-responsibility class.
If you add a getter and setter method to a single-responsibility class, then it meets all criteria of an encapsulated class.

SOLID principles2

SOLID principles3

Advantage: The advantage of programs that follow SRP is that you simply can change the behavior of a function by editing the only class liable for it. Also, if one functionality breaks, you recognize where the bug is going to be within the code and may trust that only that class will break.

O: Open-closed principle

The open-closed principle (OCP) involves entities that will be widely adopted but also remain unchanged. This leads us to make duplicate entities with specialized behavior through polymorphism.
Through polymorphism, we may extend our base entity to suit the requirements of the derived entity while leaving the base intact.
Our parent entity will function as an abstract base class which will be reused with added specializations through inheritance. However, the first entity is locked to permit the program to be both open and closed.


SOLID principles4


SOLID principles5


principles6


Advantage: The advantage of OCP is that it minimizes program risk when you need to add new uses for an entity. Instead of reworking the parent class to fit a work-in-progress feature, you create a derived class break away from the classes currently present throughout the program. We can then work on this unique derived class, confident that any changes we make thereto won’t affect the parent or the other derived class.
We can then work on this unique derived class, confident that any changes we make thereto won’t affect the parent or the other derived class.

L: Liskov substitution principle

The principle says that any class must be directly replaceable by any of its subclasses without error. In other words, each subclass must maintain all behavior from the parent class as well as the new behaviors unique to the subclass. The child class must be able to process all the same requests and complete all the existing tasks as its parent class.
principles7


principles8


principles9


Advantage: The advantage of LSP is that it quickens the development of the latest subclasses as all subclasses of an equivalent type share a uniform use.
You can trust that each newly created subclasses will work with the prevailing code. If you opt that you simply need a replacement subclass, you’ll create it without reworking the prevailing code.

I: Interface segregation principle

The interface segregation principle (ISP) requires that classes only be ready to perform behaviors that are useful to attain their end functionality. In other words, classes don’t include behaviors that are not in use.
This relates to our first SOLID principle in that together these two principles strip a class of all variables, methods, or behaviors that do not directly contribute to their role. Methods must contribute to the main goal in their entirety.

principles10


principles11

D: Dependency inversion principle

principles12


principles13


Advantage: The advantage of DIP is that decoupled programs require less work to change. Webs of dependencies across your program mean that one change can affect many separate parts. The second part may be thought of as “the abstraction isn’t affected if the definitions are changed”. The abstraction is mainly the user-facing part of the program.

People having good knowledge of Financial accounting can get an Accounting Certification Exam from StudySection to increase their chances of getting a job in this field. You can get a foundation level certification if you are new to Financial accounting or you can go for advanced level certification if you have expert level skills in Financial accounting.

Leave a Reply

Your email address will not be published. Required fields are marked *

fiteesports.com rivierarw.com cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri