name for a factory class

?

-

what would be an appropriate name for a factory class that has a public
static method that accepts a string and returns a Message or Reply
object depending on the command found in the string?

e.g:
string format : prefix command param1 param2 ....
will return a Message if command is ABC
will return a Reply if command is 123
 
I

iamfractal

- said:
what would be an appropriate name for a factory class that has a public
static method that accepts a string and returns a Message or Reply
object depending on the command found in the string?

e.g:
string format : prefix command param1 param2 ....
will return a Message if command is ABC
will return a Reply if command is 123

Hi, nobody!

For a start, do distinguish between factory method and abstract
factory; there is no, "Factory pattern." I'll presume here, judging by
the simplicity of the problem (i.e., how well you've simplified the
problem) that you're looking for the name of a factory method - do let
me know if I'm wrong.

A factory method doesn't just create objects: it must return a
superclass common to all objects it creates. In your case, there must
be some class (or interface, if you're a Java/C#-dude) that both
Message and Reply extend; let's call this class Text. This being the
case, a good name for your factory method would be createText().

..ed

www.EdmundKirwan.com - Home of The Fractal Class Composition.
 
?

-

A factory method doesn't just create objects: it must return a
superclass common to all objects it creates. In your case, there must
be some class (or interface, if you're a Java/C#-dude) that both
Message and Reply extend; let's call this class Text. This being the
case, a good name for your factory method would be createText().

hi ed, would getInstance() be ok too?
i notice there is a getControlInstance(Control ctl)
in the javax.naming.ldap.ControlFactory class
 
I

iamfractal

- said:
hi ed, would getInstance() be ok too?
i notice there is a getControlInstance(Control ctl)
in the javax.naming.ldap.ControlFactory class

Hi, again!

"getInstance()" is not a great name, because that's usally (or should
we say, "Conventionally") the name of the method that returns the lone
instance of a singleton; so people may think that this method is
returning an instance of the factory, rather than an instance of one
of the implementations that the factory's creating.

An analogy with the Sun name you provided above would be,
"getTextInstance()," again referring to some superclass common to both
of your implementations.

(It should be noted, however, that naming a method perhaps isn't so
big a deal: choose a name, and move on. If similar naming questions
arise, then be consistent. There'll be plenty of other nastinesses
more deserving of your time.)

..ed

www.EdmundKirwan.com - Home of The Fractal Class Composition.
 
P

Patricia Shanahan

(e-mail address removed) wrote:

....
(It should be noted, however, that naming a method
perhaps isn't so big a deal: choose a name, and move on.
If similar naming questions arise, then be consistent.
There'll be plenty of other nastinesses more deserving of
your time.)
....

Difficulty finding even one good name for a method may
indicate a deeper problem that does need to be addressed.
Ideally, a method has a single cohesive purpose, and the
name reflects that. A method that does this or that, without
an obvious purpose that covers both, may not be that cohesive.

This is different from having several good names for a
method. In that case, I agree with "choose a name, and move
on". Unless it is going to be a widely distributed library
method, you can always refactor later for consistency.

Patricia
 
I

iamfractal

Patricia Shanahan said:
(e-mail address removed) wrote:

... Snoiip.

Difficulty finding even one good name for a method may
indicate a deeper problem that does need to be addressed.
Ideally, a method has a single cohesive purpose, and the
name reflects that. A method that does this or that, without
an obvious purpose that covers both, may not be that cohesive.

This is different from having several good names for a
method. In that case, I agree with "choose a name, and move
on". Unless it is going to be a widely distributed library
method, you can always refactor later for consistency.

Patricia

Verily doth Patricia speaketh the truth.

..ed

www.EdmundKirwan.com - Home of The Fractal Class Composition.
 
C

Chris Uppal

Patricia said:
Difficulty finding even one good name for a method may
indicate a deeper problem that does need to be addressed.

I agree entirely.

But in this case I suspect that the difficulty is caused by focussing on the
Pattern (with a capital 'P') rather than on what the code is /for/. Just going
from the minimal information that the OP presented, it sounds as if
parseCommand() might be a decent name -- the fact that its acting as a factory
for <whatever the common class of Message and Request is>, is less important
than that it's parsing the command string.

OTOH, if the command string is /really/ only being used to parameterise the
factory method (an idea I dislike, btw. /Strongly/ dislike...), then I don't
see anything wrong with something simple like makeXxxx() (where Xxx is the
mysterious common superclass).

Similar observations hold if the OP is actually considering a factory object of
some kind, rather than a factory method.

-- chris
 
I

iamfractal

Chris Uppal said:
Patricia Shanahan wrote:

Clippity snip.
OTOH, if the command string is /really/ only being used to parameterise the
factory method (an idea I dislike, btw. /Strongly/ dislike...),

-- chris

Hi, Chris!

Just curious: what do you dislike here?

(A) Parameterized factory methods in general.
(B) Using a string as the parameter of a parameterized factory method.

I only ask because I use factory methods a lot, so if (A), I'd be keen
to see what you use instead.

If (B), well I tend to parameterize with an int so I can use a switch.

Thanks,

..ed

www.EdmundKirwan.com - Home of The Fractal Class Composition.
 
C

Chris Uppal

OTOH, if the command string is /really/ only being used to parameterise
the
factory method (an idea I dislike, btw. /Strongly/ dislike...),
[...]
Just curious: what do you dislike here?

(A) Parameterized factory methods in general.
(B) Using a string as the parameter of a parameterized factory method.

I only ask because I use factory methods a lot, so if (A), I'd be keen
to see what you use instead.

I have nothing at all against factory methods -- I like them and think they
should be used more than they are.

No, my objection is to encoding important structural information in Strings.
If a string comes from outside the program and needs to be parsed, then that's
fair enough, but when one part of a program communicates with another part of
the same program using (what amounts to) a separate programming language
encoded as Java strings, then that strikes me as obfuscation for obfuscation's
sake.

(I'm not, btw, claiming that there can /never/ be good reasons to use such a
technique, just that they don't come up very often.)

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top