SOLID OOP Principle
There are five OOP principles named as SOLID. Each character in the word SOLID stands for a principle which is nothing but a guideline for better design of OOP applications. These five principles are outlined below:
S : Single Responsibility Principle – This principle states that every entity should be assigned only single responsibility. In other words, it recommends for high cohesion.
O : Open Closed Principle – This principle recommends using inheritance and code reuse so as to provide abstraction for complex operations. The closed word is used to mention that the base entities should be defined in terms of interfaces or abstract classes.
L : Liskov Substitution Principle – The Liskov substitution principles guides that one should be using the base class for invoking operations on concrete classes. However it also mentions that the behavior of concrete class method should not be stronger than the one expected from base class. One important point to mention here is that the logic would of concrete class specific for example area method for Square and Rectangle classes will use different formula but eventually they do calculate the area for specific geometry.
I : Interface Segregation Principle – This principle asks the designers to go for different interfaces for different requirements. For example there should be different interface for Stack, Queue and Tree and one should not be using a generic interface named DataStructure for these three different implementations.
D : Dependency Inversion Principle – It is a common scenario for one entity to be dependent on another and can’t be avoided. But usually developers tend to provide a quick fix by making one entity depend upon the details another one. By using abstractions, one can avoid the use of details and code to abstractions. A common example is to use a XMLParser class to parse an XML containing Employee data than to add a “parse” method in the Employee class itself.