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

Microsoft moving to Live (Online sofware services)

Microsoft plans to launch Internet-based complements to its core products(Windows and Office), that create opportunities for the company to sell online subscriptions and advertising. Windows Live is a set of Internet-based personal services, such as e-mail, blogging and instant messaging. Office Live will come in both ad-based and subscription versions that augment MS' Office suite. The programs won't replace the paid software but instead seem aimed at capturing its online share. Windows Live at Live.com . From BBC The move to online software services is closely linked to the spread of high-speed access to the internet, as online software services are only as good as a user's access to the web. Mr Gates, who is Microsoft's chairman and chief software architect, said the strategic shift would change his company's approach to doing business: "We are trying to put a 'service plus software' mentality into many of the product groups inside Microsoft."