DEV Community

Tarun
Tarun

Posted on

Is it still relevant to use OOPs in 2022?

This is the first ever post in my life. Don't get me wrong.

I feel like Object Oriented Programming is an overhead. It adds more complexity to the project.

This is what I think.

I want to know your opinion on this.

Thank you!!

Top comments (1)

Collapse
 
robertradnai profile image
Robert Radnai • Edited

Above a few hundred lines of code, I need to start limiting the complexity of the app by using some architectural patterns and principles. For example, dependency injection can be used to provide some interchangeable behaviour to another object. Let's say you want to save a string to a file. You can then create and use a StringToFile object:

string_saver = StringToFile(file_path)
string_saver.save(string_to_save)
Enter fullscreen mode Exit fullscreen mode

Later, you are asked to save the string to a key-value store instead. You suddenly have new parameters:

string_saver = StringToKeyValueStore(conn_str, key)
string_saver.save(string_to_save)
Enter fullscreen mode Exit fullscreen mode

However, because the save function has one argument only, which is the string to be saved (and not the file path), the rest of your application won't notice that you changed the storage method.

Whether you implement this in OOP or in functional programming style (just as well, whether in a dynamically typed or in a statically typed language) is up to you. In Java, you need to create an interface first. In Python, due to the duck typing, you don't need one. In a functional language, you can use currying or partial functions to pre-configure certain function arguments.

To me, in actual projects, the real question is whether I choose to use immutable or mutable objects.