SOLID Principles C#
S – Single responsibility principleIt means a class is responsible for only single entity, it should not contain multiple components. Like for example, if a class has an entity of Fetching Employee records, then it should not have fetching of Salary details.
O – Open/Closed PrincipleOpen for extension and closed for Modification, it means if I have an class and have multiple functions which are inter-related, if in future I want to add/modify the method I have to do it in the same class which is not a best practice. It’s good to have different classes by using single responsibility principle. By creating an Abstract class you can put common functionality in Abstract Base class and inherit those into derived classes. So here we are giving extension to derived classes via Base class.
L- Liskov substitution principleYou will have full implementation for your virtual method in parent class then we can easily replace this method in derived/child class. So, to avoid this thing we should use Interface which doesn’t have implementation in his Parent Class only definition.
I – Interface Segregation principleConsumer of an interface should not be forced to use all of its methods, if the client does not want to or does not need them. If you have a BIG interface and it’s not inter-related then break those into multiple interfaces.
D – Dependency Inversion PrincipleInversion of control is the actual mechanism using which we can make the higher level modules depend on abstractions rather than concrete implementation of lower level modules. To achieve this we have to use Interface as Base class and we can inherit those Interfaces to base/Derived Classes.
Dependency Injection is mainly for injecting the concrete implementation into a class that is using abstraction i.e. interface inside
Constructor injection
Method injection
Property injection
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: