Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30591

Re: a question about factory method

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: a question about factory method
Date 2014-12-19 01:39 +0100
Message-ID <cfhaduF4j02U1@mid.individual.net> (permalink)
References (1 earlier) <m6usaq$6bg$1@dont-email.me> <ae5dcc85-b23a-4ee3-94b3-350e585f502d@googlegroups.com> <m6v1e2$u2d$1@dont-email.me> <74e17e36-3ccb-45c4-b50a-439d2799e3c7@googlegroups.com> <m6v9k5$5fb$1@dont-email.me>

Show all headers | View raw


On 18.12.2014 20:24, Eric Sosman wrote:

>      As to *how* a factory method might choose which of several classes
> to return, you already illustrated one way (paraphrased):
>
>      public static Calendar getInstance(Date aDate, int choice) {
>          if (choice == 1) {
>              ... //return a GregorianCalendar object
>          } else if (choice == 2) {
>              ... //return a MayanCalendar object
>          } else if (choice == 3) {
>              ... //return a JulianCalendar object
>          } else {
>              return null;
>          }
>      }
>
> To me, this doesn't seem a huge advantage: The caller who writes
> `getInstance(date, 2)' could just as easily write `new MayanCalendar()'
> with about the same effect.

The crucial point is that the caller does not need to know the criteria 
when to create what type.  That _is_ a huge advantage.

Cheers

	robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

a question about factory method John <xsli2@yahoo.com> - 2014-12-18 05:57 -0800
  Re: a question about factory method Robert Klemme <shortcutter@googlemail.com> - 2014-12-18 15:28 +0100
  Re: a question about factory method Silvio <silvio@internet.com> - 2014-12-18 15:43 +0100
  Re: a question about factory method Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-12-18 10:37 -0500
    Re: a question about factory method John <xsli2@yahoo.com> - 2014-12-18 08:04 -0800
      Re: a question about factory method Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-12-18 12:04 -0500
        Re: a question about factory method John <xsli2@yahoo.com> - 2014-12-18 10:43 -0800
          Re: a question about factory method Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-12-18 14:24 -0500
            Re: a question about factory method Robert Klemme <shortcutter@googlemail.com> - 2014-12-19 01:39 +0100
  Re: a question about factory method Roedy Green <see_website@mindprod.com.invalid> - 2014-12-18 13:43 -0800

csiph-web