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


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

Re: a question about factory method

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: a question about factory method
Date Fri, 19 Dec 2014 01:39:25 +0100
Lines 32
Message-ID <cfhaduF4j02U1@mid.individual.net> (permalink)
References <ff7f0941-582f-4a6f-83fd-2fa71434ff46@googlegroups.com> <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>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net bjpaTlD9WHx7T/VnMZipvAv3Zvuu/MpCU9dcizqvcRK9zGmh0=
Cancel-Lock sha1:FasZ8RyXL61rGx9hhY5ESGTixSE=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
In-Reply-To <m6v9k5$5fb$1@dont-email.me>
Xref csiph.com comp.lang.java.programmer:30591

Show key headers only | 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