Re: Design Question
Rhino wrote:
I have a class named StringUtils containing several utility methods.
markspace wrote:
I asked aquestionlike this here long ago. What I think now is that
you almost certainly should make the class final, and all the methods
static.
If you do need to keep state, make a new class, don't reuse the
StringUtils, except as a factory.
Rhino wrote:
Sorry, I'm not following this strategy.
I'm not entirely sure what constitutes 'state' in this context but I
Same thing it means in any other context - "state" is the aggregation
of the observable aspects of the (class or instance) object, i.e., the
values of its attributes, in particular, those that affect its
behavior.
markspace is telling you that if you write a class to be stateless,
then need to add state, it's not a good idea to mingle state with a
stateless class. You're better off separating the behaviors into a
stateless class and a stateful one.
suspect that the Locale-specific messages I am generating may qualify.
Depends on how you do it - if you store the Locale as part of the
state, then yes, it affects things.
As I've explained in my reply to Lew's first response, I am generating
Locale-sensitive error messages. I have two constructors. One
Constructors means no longer being all static.
constructor has no parameters and uses the default Locale; the other
constructor has the Locale as its parameter and generates messages
appropriate for that Locale. If this counts as "state" for the
Is it an observable attribute of the object?
Does its value affect the object's behavior in any way?
Does the value persist between method calls?
purposes of our current discussion, I'm not clear on what you're
State is state, purpose notwithstanding.
proposing. How do I use StringUtils as a factory to feed the new class
that you are suggesting?
You add a factory method to create an instance of the stateful class.
--
Lew