Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Practical uses of OOP

Tags:

oop

paradigms

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?

like image 425
yretuta Avatar asked Nov 19 '09 05:11

yretuta


Video Answer


2 Answers

My personally view: context

When you program in OOP you have a greater awareness of the context. It helps you to organize the code in such a way that it is easier to understand because the real world is also object oriented.

like image 173
AndersK Avatar answered Jan 10 '23 23:01

AndersK


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.

like image 38
daotoad Avatar answered Jan 11 '23 00:01

daotoad