Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Interface with implied Constructor Date: Mon, 15 Jul 2013 20:45:31 +0200 Lines: 54 Message-ID: References: <925adeb1-65b5-4a50-86a8-4f04784f8da0@googlegroups.com> <51df65bd$0$52780$742ec2ed@news.sonic.net> <51e41c16$0$52743$742ec2ed@news.sonic.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net sRqE00fn7sbT2tM2xmgXiQfntYrQcmPNUltPjNGMU7DaWaR1w= Cancel-Lock: sha1:TYyllJdhbaE4fQhnLm9yCO+42Gw= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 In-Reply-To: <51e41c16$0$52743$742ec2ed@news.sonic.net> X-Antivirus: avast! (VPS 130715-0, 15.07.2013), Outbound message X-Antivirus-Status: Clean Xref: csiph.com comp.lang.java.programmer:24742 On 15.07.2013 17:58, Kevin McMurtrie wrote: > In article , > Robert Klemme wrote: > >> On 12.07.2013 04:11, Kevin McMurtrie wrote: >> >>> There's a builder pattern than works. It's a little ugly but it's what >>> you have when you can't use abstract classes for some reason. Move >>> around the interfaces as you see fit. >> >> >> >> I'd call that "factory pattern". Why did you pick "builder"? > They're similar. I've seen the term "builder" used more often when the > construction is done by the implementor and "factory" more often when > the construction is performed by a single system. Builder also has a > pattern of SomeThing a= new > Builder().with(Options.B).add(x).add(y).addAll(Z).makeImmutable(); It's > a way to specify arguments after construction without allowing access to > a partially built object. But you do not use that feature of chaining in your sample code. To me that's a plain factory. If you had taken advantage of Builder you would have had an interface like this, I believe: interface MyThing { ... } public interface MyThingBuilder { MyThingBuilder addArg1(int arg1); MyThingBuilder addArg2(int arg1); MyThing finish(); } The consistency checking ("Do we have all the arguments?") is put into the MyThingBuilder implementation and the client can rely on the returned MyThing to be complete so not all methods of MyThing have to check state (a concern that has been voiced). It's a bit like Command pattern applied to object construction: the command object's configuration methods (addArg1 and addArg2 above) replace constructor arguments and the construction is eventually done by a no argument method. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/