Search code examples
oopparadigms

Practical uses of OOP


I recently had a debate with a colleague who is not a fan of OOP. What took my attention was what he said:

"What's the point of doing my coding in objects? If it's reuse then I can just create a library and call whatever functions I need for whatever task is at hand. Do I need these concepts of polymorphism, inheritance, interfaces, patterns or whatever?"

We are in a small company developing small projects for e-commerce sites and real estate.

How can I take advantage of OOP in an "everyday, real-world" setup? Or was OOP really meant to solve complex problems and not intended for "everyday" development?


Solution

  • The good things about OOP come from tying a set of data to a set of behaviors.

    So, if you need to do many related operations on a related set of data, you can write many functions that operate on a struct, or you can use an object.

    Objects give you some code reuse help in the form of inheritance.

    IME, it is easier to work with an object with a known set of attributes and methods that it is to keep a set of complex structs and the functions that operate on them.

    Some people will go on about inheritance and polymorphism. These are valuable, but the real value in OOP (in my opinion) comes from the nice way it encapsulates and associates data with behaviors.

    Should you use OOP on your projects? That depends on how well your language supports OOP. That depends on the types of problems you need to solve.

    But, if you are doing small websites, you are still talking about enough complexity that I would use OOP design given proper support in the development language.