Re: Design Question
Lew wrote:
Rhino wrote:
I'm not entirely sure what constitutes 'state' in this context but I
markspace wrote:
It basically means "an instance variable."
Unless you're talking about a static variable. That's state, too.
The former is instance state. The latter is class state, or "static"
state.
Yes, but often creating a singleton object like this is pretty bad.
(Note that the normal singleton pattern actually uses instance variables
for the object state.) At least in my opinion. It's pretty difficult
to test, can't be extended and hard to use since it doesn't actually
have a constructor, just a "global state variable." Globals are bad.
public class StringUtils {
private static Locale locale;
private StringUtils() {}
public static void setLocale( Locale loc ) {
locale = loc;
}
public static String count( String s, int count ) {
...
}
...
}
This is pretty ugly design, imo. There's a few patterns it works for,
but they're not common. I don't think the OPs utility class would be a
good choice. Yes, I'm making an assumption here, but based on what he's
told us, I think it's the right assumption.