It might look strange, but I've encountered many times code which was not object-oriented in practice, although it had all the syntactic traits to count as such, e.g. there were plenty of usages of keywords like class.

There seems to be something about object-orientedness that scares programmers. It is perhaps the idea that objects use “too much memory”. Sure, that can still be true on embeded devices or IoT, but generally speaking, having a lot of RAM has become so commonplace, that it's not an issue any longer.


First of all, what does it mean to “use objects”?

Obviously, it means to have a class first. A class is a template, a blueprint of data (called also attributes, fields in various languages) and processes (called methods).

Creating, having and using objects though is not just that, it's also actually creating them. A common way to do it is by using the keyword new.

Only when you use it, are you creating objects.

Disadvantages of not using objects

Conversely, it means also that you should not use keywords like static. Static breaks out of object-orientedness and makes the method or data belong to the blueprint, instead of each individual instance created using that blueprint.

What are the disadvantages of not using objects? I would say, the most important drawback is the inability to use polymorphism. This happens because in places where you'd call an object, you call a class instead, something like MyClass::myMethod(). This leads to the inability to swap out the concrete object/class used at runtime, dynamically.

This also happens to make the code less testable, because you cannot swap out components with your test doubles.

There is also the counterpart advice to “use objects”, that is to use functions. I agree to this, but there is an observation that needs to be described:

Sometimes, you will create a helper stand-alone function for good reasons. When a new requirement is added, you should re-evaluate its use, and if necessary, make it a helper class or a service. This allows you to use all the features of object-orientedness, like:

  • using polymorphism, tell, don't ask
  • encapsulating data