DEV Community

Dibyojyoti Sanyal
Dibyojyoti Sanyal

Posted on • Originally published at cloudnativemaster.com

What simplicity means in OO design principles ?

Simplicity is one of the Object Oriented Design Principles that helps developers keep the complexity low in an object oriented program.

Do not code for future

It says, a class and its method should be as simple as possible, the code should do exactly what it should do, nothing more. We should refrain from anticipating some functionality for future and implement it for completeness. It's better to code what is known as of now and code in a way that it can be easily extended when new functionality is needed.

Do not provide many arguments

Sometimes programmers add more arguments to methods to make it more generic so that it can handle a lot of cases. But in reality all parts of the code may not be executed because all the possible scenarios the programmer thought of, is not happening now. just write what is known to be happening and don't make your method a generic one.

Detect reusable logic and refactor

If you anticipate you are writing a logic part of which can be used later in some other cases, break that method into parts, white the reusable logic in separate method(s). Call the reusable method from another method.
An easy way to detect this is, when during development you need to refactor a certain part once that means it might have to be modified later too. So better to put an extra effort to refactor it so that later a refactoring is not needed, otherwise just leave as it is. You can use design patterns to refactor the code and write a more general solution but design patterns do come with more code and complexity. So if the situation demands it then only apply it.

To read the main blog post with a concrete example please refer this link
To read all my posts related to Object Oriented Design please refer this link

Top comments (0)