name for a factory class

Discussion in 'Java' started by -, Mar 21, 2005.

  1. -

    - Guest

    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
     
    -, Mar 21, 2005
    #1
    1. Advertising

  2. -

    Guest

    - <> wrote in message news:<423e36be$>...
    > 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.
     
    , Mar 21, 2005
    #2
    1. Advertising

  3. -

    - Guest

    wrote:
    >
    > 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
     
    -, Mar 21, 2005
    #3
  4. -

    Guest

    - <> wrote in message news:<>...
    > wrote:
    > >
    > > 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


    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.
     
    , Mar 21, 2005
    #4
  5. 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
     
    Patricia Shanahan, Mar 21, 2005
    #5
  6. -

    Guest

    Patricia Shanahan <> wrote in message news:<pFC%d.1147$>...
    > 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.
     
    , Mar 22, 2005
    #6
  7. -

    Chris Uppal Guest

    Patricia Shanahan wrote:

    > 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
     
    Chris Uppal, Mar 22, 2005
    #7
  8. -

    Guest

    "Chris Uppal" <-THIS.org> wrote in message news:<423ffa3d$0$38044$>...
    > 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.
     
    , Mar 23, 2005
    #8
  9. -

    Chris Uppal Guest

    wrote:
    >
    > > 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
     
    Chris Uppal, Mar 23, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike S
    Replies:
    0
    Views:
    23,012
    Mike S
    Sep 16, 2004
  2. Medi Montaseri
    Replies:
    17
    Views:
    876
    Medi Montaseri
    Sep 3, 2003
  3. Simon Elliott
    Replies:
    0
    Views:
    378
    Simon Elliott
    Jan 11, 2005
  4. C#
    Replies:
    4
    Views:
    411
  5. Alan
    Replies:
    4
    Views:
    251
    Bill Felton
    Jan 27, 2011
Loading...

Share This Page