Illusions of being Object Oriented

Object Oriented Programming is a programming paradigm which is organised around objects instead of the logic. Under this approach every thing is an object, only objects can interact with each other.

First we need to identify all the objects and then we generalise them as classes on the basis of Single Responsibility Principle i.e every single class should have only one job.

The most basic concept that we need to follow is encapsulation which means inclusion of all the resources of an object that it needs. All the state variables must be private which means that they should not be accessed from outside the object by following the principle of “Tell Don’t Ask”.

The most important requirement of defining a class is that it must have state and behaviour both. But in practice we often define a class having state but not behaviour or vice versa. But what is the point of having such class? Aren’t we just convincing ourselves that our design is object oriented but actually it is not?

The use of getter and setter functions is also an illusion of being object oriented. We define variables as private so as to maintain encapsulation but then we define getter and setter public methods to give access to the private data so anyhow we are breaking the encapsulation. The goal of our design should be to maintain maximum encapsulation.

We should also avoid using private methods within a class reason being the same for not using global variables. If we remove the class wrapper from these methods and variables then they will just convert to a C program having functions and global variables.

Reaching proper Object Oriented Design is an ideal case but we must try our best to reach the maximum which is possible.

Happy Coding!

Show your support

Clapping shows how much you appreciated Prakhar Mathur’s story.