Path: csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.xdsl-89-1-55-190.netcologne.de!not-for-mail From: Patrick Roemer Newsgroups: comp.lang.java.programmer Subject: Re: Parameterized Factory with additional parameter requires new interface? Date: Fri, 28 Oct 2016 15:17:27 +0200 Organization: news.netcologne.de Distribution: world Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 28 Oct 2016 13:17:27 +0000 (UTC) Injection-Info: newsreader4.netcologne.de; posting-host="xdsl-89-1-55-190.netcologne.de:89.1.55.190"; logging-data="17372"; mail-complaints-to="abuse@netcologne.de" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.24) Gecko/20100411 Thunderbird/2.0.0.24 Mnenhy/0.7.6.0 X-Mozilla-News-Host: news://news.netcologne.de In-Reply-To: Xref: csiph.com comp.lang.java.programmer:35876 Responding to mike: > public interface Factory { > > /** > * Creates a new equipment type instance > * > * @param resource > * @return equipment instance of type T > */ > public T create(R data); > > } > > > Now we need an additional create method that takes an additional parameter of type P. > > > public interface Factory { > > /** > * Creates a new equipment type instance > * > * @param resource > * @return equipment instance of type T > */ > public T create(R resource); > > /** > * Creates a new equipment type instance > * > * @param resource > * @param parameter > * @return equipment instance of type T > */ > public T create(R resource,P parameter); > } > > > Then in the code I get: > > Incorrect number of arguments for type Factory; it cannot be parameterized with arguments If this was valid... Factory factory = ... ...how should compiler (and/or runtime) handle this? XXXresource res = ... XXXtype t = factory.create(res, "foo"); > Does this mean we have to create a new parameterized interface for each additional create() method that we have? What additional create() methods do you expect? Either your new design is valid. This basically would mean that you need a P in addition to an R to be able to create a T, but that there's an implied default value for any conceivable P that can be used to create a T only given an R, so the "old" method signature is kept as a convenience for this case. Then you should be able to come up with a legitimate (not just "dummy") concrete type for P in your existing instantiations. Or the two factory approaches are independent. There might be types R where there simply is no additional P value required to create a T. Conversely, one could imagine types R and P such that the second method could be implemented, but not the first one, i.e. there's no default value for P. Then these two approaches should go to different interfaces. Best regards, Patrick