+ 6
When writing a program, is an OOP approach always better than functions?
If so, where can I find good excercises to help me "model real world objects"? I'm finding it hard to write classes that actually do that
9 Réponses
+ 6
Thank you John Wells, I will take a look at your post 👍
+ 5
No, there are many programs that functional approach makes more sense. Just look at most beginner Java programs. If all class methods are static, OOP did not make sense for this program.
Given the case where OOP does make sense, use it. I suggest make a code play a card game. The deck of cards and players make sense to be objects. The game itself can go either way. But, in that case I always use OOP. If you want suggestions on a game, I've posted plenty here.
https://www.sololearn.com/Discuss/1270852
+ 5
Avinesh, the functions you are talking about would be methods, right? What I mean is when is OOP a must?
+ 5
Avinesh OK, so that's what I have to figure out next 😅
+ 4
Alina Sansevich you can say that functions are a part of OOPS. For eg-
If you want to print a pattern then you use functions and there is no need of oops.
But if you want to show student details then you need to make use of oops and the class definitely has functions inside it to perform various tasks.
+ 4
especially if you want to make your data secure
using classes makes your program more efficient
though in modern compilers the change noticed is generally unnoticed still in my view sticking to the OOPS concepts has its advantages 😊
+ 3
Alina Sansevich OOP is a must when you really want to replicate a real life entity.
It could be a person, a box, a game, anything that you wish.
+ 1
You should only approach throughout OOP when you want to make a data model with some specific functions and a represention. Otherwise it's always good to not approaching through OOP. I mean you will not want to provide a model data structure for just a simple problem. And OOP often gets much complex, especially for the beginners.