Does it ever make sense to create a class that consists only of member functions and has no member variables? Basically, a class that exists just to physically group functions that share a purpose but don't neccessarily operate on the same set of data.
Name:
Anonymous2006-04-02 22:47
Isn't that what namespaces/packages are for?
Name:
Anonymous2006-04-02 23:15
Imagine you have geometry package, you might want to change the geometries by passing in a class which implements the geometry.
Namespaces don't necessarily cover that.
Name:
Anonymous2006-04-02 23:17
i make abstract classes that only consist of abstract member functions all the time. can be very useful.
haven't needed to make concrete classes without at least one member variable yet, but i can't imagine they're useless. i've just not required one before now.
Name:
Anonymous2006-04-03 3:43
>>1
In Java, yes it does, provided you declare them all as static. In general any method that doesn't reference the members of an object should be static. Think of the Math class; you don't instantiate it, you just use its methods. Most languages allow some alternative form of modularisation, but in Java's (stupid) version of OO everything must be in a class, even things like the sin() function.
Name:
Anonymous2006-04-03 4:09
>>5
Actually, I'm thinking more about C++. The answer, as you pointed out, is obvious in Java.
Name:
Anonymous2006-04-03 5:06
>>6
In that case I'll say no. A class consisting entirely of concrete functions and no member variables would never need to be instantiated. You could subclass it to include the functions in your own class, but that's no more or less convenient than using a namespace. In fact using a namespace would be better, because it would avoid multiple inheritance related discomfort.