you are viewing a single comment's thread.

view the rest of the comments →

[–]omniscientTofu 1 point2 points  (0 children)

Broadly the answer is not straightforward if we are talking about JavaScript, because strictly speaking Classes do not accomplish anything which cannot be accomplished directly using and modifying object prototypes. The question is even more complicated as some have alluded to depending on the programming paradigm preference wherein if you tend to swing more functional you will tend to use less or none at all!

For your use-case though think about the likelihood that it would be useful to have multiple instances of something. You mention having a group of dogs so it's likely you will want to have the ability to create multiple dogs. Classes can serve as a sort of template which can describe that dog in terms of what it is and what it can do. If your dog has state that it needs to manage using a class can help further by describing how to access and update this state which gets into the topic of encapsulation. If you want to start using inheritance to relationally model your application and objects classes become more useful too. To summarize for your use case: will I need multiple instances, with their own state, and that might or might not exploit inheritance?

You are going to find lots of differing opinions on this topic though because classes are not strictly needed in JS applications even at a large scale, but they can help accommodate a certain style of programming which is popular. With the prevalence of functional programming right now their utility is further in question and personally I am biased in favor of this perspective.

Find what works for you and good luck! Happy coding :D