Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
It depends. Regarding "grouping functions/methods": as a general rule, you should group things that make sense to be together. Yes, it's a very broad and generic rule, and somewhat subjective. How...
Answer
#1: Initial revision
It depends. Regarding "grouping functions/methods": as a general rule, you should group things that make sense to be together. Yes, it's a very broad and generic rule, and somewhat subjective. _How_ you group those things, though, depends on a lot of factors. The other answers covered some aspects, I just want to add another one: # Language constraints In Java and C# everything must be inside a class. Hence, there's no way to create a top-level independent function in those languages. That's why, for example, the `Math` class (in both languages) has only a bunch of static methods (such as `Math.floor`/`Math.Floor` or `Math.sqrt`/`Math.Sqrt`) and static fields/constants (such as `Math.PI` or `Math.E`), and it can't be instantiated (you can't do `new Math()`). That's the only way - imposed by the languages characteristics - to group lots of "independent functions" that make sense to be together. Those methods and fields don't need an instance, because they don't depend on any internal state (no instance variables needed), they just provide mathematical calculations that could all be top-level functions/variables. But the languages don't allow that, so they must be inside a class. In Python, on the other hand, the `math` module provides the same functionalities ("math stuff") as independent functions (such as `math.floor` or `math.sqrt`) and variables/constants (`math.pi`, `math.e`). _Actually, they're not fully "independent", as they belong to the module, but anyway..._ Those functions don't need an internal state (AKA instance variables), so there's no point in creating a class for them. As the language doesn't require the creation of a class, they can simply be functions/variables and grouped together in a module. In C there are no classes at all, but you can still group things together. Many mathematical functions can be found at `math.h` as "top-level independent functions". So, to answer the question: > Are there practical reasons for designing/implementing a method(s)-only class/object? I'd say some of the reasons might be: - the language requires a class and don't allow me to do it differently, or - the methods need some internal state of an instance, hence they need a class If the language doesn't have classes (or doesn't require everything to be inside a class), and the functions would work best as top-level/independent, then grouping things without classes, using whatever other mechanism the language offers, would be preferred.