Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Software engineering question

Name: Anonymous 2006-04-02 22:43

And it's not about Java (necessarily).

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: Anonymous 2006-04-02 22:47

Isn't that what namespaces/packages are for?

Name: Anonymous 2006-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: Anonymous 2006-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: Anonymous 2006-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: Anonymous 2006-04-03 4:09

>>5
Actually, I'm thinking more about C++. The answer, as you pointed out, is obvious in Java.

Name: Anonymous 2006-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.

Name: Anonymous 2006-04-03 23:44

>>7

is namespace something native to cpp? can you give an example of it and show a java equivalent? thanks, appreciated.

Name: Anonymous 2006-04-04 1:09

Yes, if by "native" you mean "part of the standard language."

c++:

namespace N {
  class C { ... };
}

Java:

package N;

public class N {
  ...
}

Name: Anonymous 2010-09-21 17:12

Usually static class don't have member variables.

Don't change these.
Name: Email:
Entire Thread Thread List