When writing a program, is an OOP approach always better than functions? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

29th Nov 2019, 5:03 PM
Alina Sansevich
Alina Sansevich - avatar
8 Answers
+ 6
Thank you John Wells, I will take a look at your post 👍
29th Nov 2019, 5:20 PM
Alina Sansevich
Alina Sansevich - avatar
+ 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
29th Nov 2019, 5:15 PM
John Wells
John Wells - avatar
+ 5
Avinesh, the functions you are talking about would be methods, right? What I mean is when is OOP a must?
29th Nov 2019, 5:18 PM
Alina Sansevich
Alina Sansevich - avatar
+ 5
Avinesh OK, so that's what I have to figure out next 😅
29th Nov 2019, 5:24 PM
Alina Sansevich
Alina Sansevich - avatar
+ 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.
29th Nov 2019, 5:11 PM
Avinesh
Avinesh - avatar
+ 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 😊
30th Nov 2019, 5:30 PM
Aditya
Aditya - avatar
+ 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.
29th Nov 2019, 5:22 PM
Avinesh
Avinesh - avatar
+ 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.
1st Dec 2019, 5:07 AM
Ishmam
Ishmam - avatar