Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35876
| From | Patrick Roemer <sangamon@netcologne.de> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Parameterized Factory with additional parameter requires new interface? |
| Date | 2016-10-28 15:17 +0200 |
| Organization | news.netcologne.de |
| Message-ID | <nuvj57$gus$1@newsreader4.netcologne.de> (permalink) |
| References | <d1c8beb2-3ef7-4965-afa0-4cb0902c02fb@googlegroups.com> |
Responding to mike:
> public interface Factory<T, R> {
>
> /**
> * 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<T, R,P> {
>
> /**
> * 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<T,R,P>; it cannot be parameterized with arguments <XXXtype, XXXresource>
If this was valid...
Factory<XXXtype, XXXresource> 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
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Parameterized Factory with additional parameter requires new interface? mike <mikaelpetterson@hotmail.com> - 2016-10-27 23:51 -0700
Re: Parameterized Factory with additional parameter requires new interface? j4n bur53 <janburse@fastmail.fm> - 2016-10-28 10:27 +0200
Re: Parameterized Factory with additional parameter requires new interface? Andreas Leitgeb <avl@logic.at> - 2016-10-28 11:59 +0000
Re: Parameterized Factory with additional parameter requires new interface? Patrick Roemer <sangamon@netcologne.de> - 2016-10-28 15:17 +0200
Re: Parameterized Factory with additional parameter requires new interface? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-28 11:12 -0400
Re: Parameterized Factory with additional parameter requires new interface? j4n bur53 <janburse@fastmail.fm> - 2016-10-28 18:07 +0200
Re: Parameterized Factory with additional parameter requires new interface? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-28 16:43 -0400
csiph-web