DEV Community

Discussion on: When do you create a function or method?

 
codevault profile image
Sergiu Mureşan

This would work most of the time but wouldn't that create too many classes if there are many such methods?

Thread Thread
 
lexplt profile image
Alexandre Plt

It could, but if you can "group" methods playing with the sames arguments (but doing different things with those) it can be pretty efficient in reducing SLOC (physical lines of code) and code complexity (IMO, in some cases creating a function with more than 4-5 arguments is better than creating a class).

To me, the most interesting thing with a class is that it handle its resources on its own, all of them, in the same place.

Thread Thread
 
codevault profile image
Sergiu Mureşan

Yup, that's why they were designed. Data with functionality. Just be careful not to group data with functionalities that don't actually deal with the data as whole but just parts of it. Or even worse, consider functionalities as objects and creating classes based on those. It can lead to so many headaches.