The objective of this article is to present mnemonic acronym, mnemonic images and tag lines for easy remembrance of Object Oriented Principles other than the SOLID object oriented principles.
The object oriented principles SOLID, introduced by Robert C Martin, are well known and easy to remember in the acronym form SOLID. The easy remembrance of the principles will aid and prompt the programmer in application of those principles in programming. Apart from the SOLID principles there are several other principles which are also relevant in the Object Oriented programming. If these principles are put in an acronym form, the remembrance and application of these principles in the programming can be made easy to the programmers. After trying for some time I have created an acronym for these principles as shown below:
|| program to Interface Not Implementation
Don't Repeat Yourself
Encapsulate What Varies
depend on Abstractions, Not Concrete classes
Least Knowledge Principle
favour Composition Over Inheritance
Apply Design Pattern wherever possible
Strive for Loosely Coupled System
Keep it Simple and Sweet / Stupid
Further, a sentence is formed by connecting the keywords of the principles as follows:
Interfaces Don't repeat Encapsulated Abstractions with Least knowledge of Composition of Hollywood principle Adopted Loosely to Keep it simple.
Since these principles are in addition to the SOLID principles, we can say, write SOLID object oriented programs with IDEAL CHALK.
Human brain is good at remembering the images rather than words. The old adage is that "A picture is worth a thousand words"
. I have created a mnemonic image for each of the object oriented principles.
INI - program to Interface Not Implementation
DRY - Don't Repeat Yourself
EWV - Encapsulate What Varies
ANC - depend on Abstractions, Not Concrete classes
LKP - Least Knowledge Principle
COI - favour Composition Over Inheritance
HOP - HOllywood Principle
ADP - Apply Design Pattern wherever possible
LCS - Strive for Loosely Coupled System
KISS - Keep it Simple and Sweet / Stupid
Here's a talk between OO guru and the Programmer
|OO Guru|| Hi! Programmer.|
Use program to Interface not Implementation (INI) principle and do program to IView so that we can use it for desktop (windows forms) application and web forms applications. Do program to IView so that we can use it for desktop (windows forms) application and web forms applications. Think what to do, not who does it.
|Programmer||OK. Don't Repeat Yourself.|
|OO Guru|| That's good. You have said the next OO principle. Don't Repeat Yourself (DRY). Change shall be made only at one place in the program. It should be reflected at other places. |
|Programmer|| Is it so! Thank you. I will follow it too. |
|OO Guru|| I have seen that you have mixed up potatoes and tomatoes. The rotten tomatoes spoilt potatoes. In OO programming also similar situation may arise. Then use the Encapsulate What Varies (EWV) principle. Don't let tomatoes spoil potatoes |
|Programmer|| It sounds sensible and your point is well taken.|
I have been waiting for the car which I have booked, till now it has not come. I have to go out.
|OO Guru|| I came to know that Car is at present not available. Only Van is available. That's why depend on Abstractions Not Concrete Classes (ANC). If you have ordered a 4 wheeled vehicle, then you might have got Van. Be generic not specific. |
|Programmer|| I understood the point. Now I order the 4 wheeled vehicle and I will take care in future. |
|OO Guru|| You are very receptive. By the way, your vehicle has arrived.|
When you go out, talk to friends not strangers. This is another OO principle called Least Knowledge Principle (LKP).
|Programmer|| Thank you for the advice. I will come back soon. By the time I come back, can you please get the analog clock replaced with digital clock in my room. |
|OO Guru||OK. I will do.
|Programmer||Why is the wall of my room is being reconstructed? |
|OO Guru||You have embedded the analog clock in the wall. Hence, to replace it with digital clock the wall is being reconstructed. If the analog clock was hung up, then it would have been easy to replace it with the digital clock. Foreseeing these complexities, OO veterans advise, favour Composition Over Inheritance (COI). |
|Programmer|| Now I understood it practically and it will become part of my vocabulary for programming.|
Please give me your phone I want to call my boss.
|OO Guru|| Hey, don't call your boss. Don't you know the Hollywood Principle (HOP), Don't Call us, we will call you. |
|Programmer|| OK OK. Then I will continue with my invention of wheel, to make the car. |
|OO Guru|| What did you say? Invention of wheel! Come on! Don't reinvent the wheel. Use the existing wheels and invent the car. In OO programming too, Apply Design Patterns (ADP), which are proven methods for the common programming tasks. What is in your hand?.|
|Programmer|| I am trying to bring 1 to 9 numbers in serial order on each face of this cube. It took so much time, but I could not succeed. |
|OO Guru|| In cube all the small cubes with numbers are very tightly coupled. Hence, you are facing the problem. Try for Loosely Coupled Systems (LCS). Don't get entangled. Take each plane with number 1 to 9. |
|Programmer|| You are awakening me with so many OO principles. How to remember and apply so many things.|
Yeah! Good question. Remember our conversation and the acronym for each of the principles and while programming, observe, which OO principle is being violated. If you cannot apply the principle as it is, don't worry. These are principles not laws. Law is a stringent rule, which should be followed. Whereas, principles are guidelines, which can be followed as per the requirement.
While driving the vehicle we apply the relevant gear as per the speed variation automatically, apply the break immediately. In Transportation Engineering the theory behind applying brake is called, PIEV theory.
According to PIEV theory the time required to apply brakes is sum of the time required for perception, intellection, emotion and volition. Before an automobile is stopped, four specific areas of activity will happen:
- Perception: The hazard is perceived.
- Intellection: Whether hazard is legitimate is determined.
- Emotion: There is an emotional factor with respect to deciding if we want to stop.
- Volition: There is the physical volition of moving the foot from to the brake pedal.
But, while driving these steps happen automatically. Similarly, the 15 OO principles (5 SOLID and 10 IDEAL CHALK) may be studied thoroughly, so that they are applied naturally while doing the Object Oriented Programming.
|Programmer|| This talk with you has instilled confidence in me. |
|OO Guru|| OK. Finally don't forget KISS.
|Programmer|| KISS! |
|OO Guru|| It's an OO principle called, Keep It Simple and Stupid (KISS). Don't beat around the bush. Be straightforward.|
|Programmer|| Thanks a lot for the inspirational guidance. |
I will be happy to see your comments and suggestions to improve the article
3 Mar 2012 - OOP word added in description. Spelling mistakes corrected. Table borders removed and text formatted
5 Mar 2012 - Sentence on comments and suggestions added