Skip to main content

SOLID - Principles of Object Oriented Class Design

The theory of SOLID principles was introduced by Martin in his 2000 paper "Design Principles and Design Patterns". The SOLID acronym was introduced later by Michael Feathers.

1. Single responsibility principle
A class should have only one reason to change

Martin defines a responsibility as a reason to change, and concludes that a class or module should have one, and only one, reason to be changed (i.e. rewritten).

"When designing our classes, we should aim to put related features together, so whenever they tend to change they change for the same reason. And we should try to separate features if they will change for different reasons." - Steve Fenton

2. Open-Closed Principle
A module should be open for extension but closed for modification.

Of all the principles of object oriented design, this is the most important.

It means simply this: We should write our modules so that they can be extended, without requiring them to be modified. In other words, we want to be able to change what the modules do, without changing the source code of the modules.

3. Liskov Substitution Principle
Subclasses should be substitutable for their base classes

This principle was coined by Barbar Liskov in her work regarding data abstraction and type theory. It also derives from the concept of Design by Contract (DBC) by Bertrand Meyer

Derived classes should be substitutable for their base classes. That is, a user of a base class should continue to function properly if a derivative of that base class is passed to it.

4. Interface Segregation Principle
Many client specific interfaces are better than one general purpose interface

The essence of the principle is quite simple. If you have a class that has several clients, rather than loading the class with all the methods that the clients need, create specific interfaces for each client and multiply inherit them into the class.

5. Dependency Inversion Principle
Depend upon Abstractions. Do not depend upon concretions

Dependency Inversion is the strategy of depending upon interfaces or abstract functions and classes, rather than upon concrete functions and classes. This principle is the enabling force behind component design, COM, CORBA, EJB, etc.


Comments

Popular posts from this blog

Team Work

Ramo Vigrahavan Dharmah

A great verse from Ramayana: आहार निद्रा भय मैथुनं च  सामान्यमेतत् पशुभिर्नराणाम् । धर्मो हि तेषामधिको विशेष:  धर्मेण हीनाः पशुभिः समानाः ॥ AhAra-nidrA-bhaya-maithunam cha samAnam_etat_pashubhir_narANAm | dharmo hi teShAm adhiko visheSho dharmeNa hInAH pashubhiH samAnAH|| Eating, Sleep, Fear and Sex ; these habits are common between human beings and animals. It is the Dharma which is the special quality of the human beings. Without the Dharma, they are similar to the animals.  Rama is The Embodiment Of Dharma.  Maaricha, while speaking to Ravana- (Aranya Kandam 37-13): रामो विग्रहवान् धर्मः साधुः सत्य पराक्रमः | राजा सर्वस्य लोकस्य देवानाम् इव वासवः || ३-३७-१३|| raamo vigrahavaan dharmaH saadhuH satya paraakramaH | raajaa sarvasya lokasya devaanaam iva vaasavaH || 3-37-13 "Rama is the embodiment of righteousness, he is an equable person with truthfulness as his valour, and as with Indra to all gods he is the king of entire world. [3-37-13] Another great phra

Procrastination to Motivation (Regulate your emotions)

You Procrastinate Because Of Emotions, Not Laziness. Regulate Them To Stop Procrastinating! There are two trains of thought – One leads to procrastination and one leads to motivation. And somewhere in between, there is a junction called anxiety. Procrastination train of thought: People procrastinate or avoid aversive tasks to improve their short-term mood at the cost of long-term goals. Procrastination is not a time management problem. It is an emotion regulation problem - we delay activities which might make us feel not-so-good. Procrastination is not laziness. Humans procrastinate because of poor emotional regulation about the outcome of tasks. In short, we often procrastinate because of perceived anxiety, stress, and poor emotional regulation about the completion of a task. Perceived anxieties make us feel ‘not so good.’ The aversion activity is a mechanism to avoid or delay the anxiety and repair the short-term negative mood. Habits like procrastination are a reaction