Thursday, 19 April 2018

Advantages of SOLID principal

Single Responsibility Principle
A class should have one, and only one, the reason to change

Benefits
More readable code
More robust
More maintainable

Smaller functions

Open Closed Principle
Software entities should be open for extension but closed for modification

Change to an entity cascades changes to dependent modules Fragile Unpredictable Modules should never change Extend behavior – add new code Don’t change the existing working code

Liskov Substitution Principle.
Derived classes must be substitutable for their base classes

Important for any program conforming to OCP Caller should not be surprised by substituting base type for subtype Virtual members must exist in derived classes Must do useful  expected workLiskov Substitution Principle

Useful work Must be implemented Expected work Should keep the behavior of the base class

Interface Segregation Principle
Make fine grained interfaces that are client specific

Deals with the disadvantage of “fat” interfaces
Clients forced to depend on interfaces they don’t use subjected to changes in that interface
MembershipProvider – forces 27 methods/properties

Benefits
Lower coupling – better maintainability
Higher cohesion – better robustness

Dependency Inversion Principle
Depend on abstractions, not concretions

Modules should not depend on modules implementing details
Depend on abstractions

1 comment: