SOLID Principle

Single Responsibility


  • S — Single responsibility principle
  • O — Open closed principle
  • L — Liskov substitution principle
  • I — Interface segregation principle
  • D — Dependency Inversion principle

Single responsibility principle – 
A class should have one and only one reason to change, meaning that a class should only have one job.

Open-closed Principle –
Objects or entities should be open for extension, but closed for modification. – implemented using abstraction. to add more code extend the class.

Liskov substitution principle – 
Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T.

All this is stating is that every subclass/derived class should be substitutable for their base/parent class. In other words, as simple as that, a subclass should override the parent class methods in a way that does not break functionality from a client’s point of view. Subtypes must be substitutable for their base types.

If we follow Single responsibility principle then Liskov substitution principle will be implemented by default.

Interface segregation principle
It states that clients should not be forced to implement interfaces they don’t use. Instead of one fat interface many small interfaces are preferred based on groups of methods, each one serving one submodule.
Classes that implement interface should not be forced to implemented method that do not use. We should write new interface. Interface should be small and not fat.

D – Dependency Inversion 

Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions.
Instead of depending on concrete class we should depend on interface.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s