>> So pass in the superset of objects you need to pass to the
>> constructors, and
>> I guess each concrete uses the subset it needs.
>
> Thats what I was thinking using the params keyword but it doesnt seem
> very elegant. Maybe I'm wrong.
Your question is a bit vague. But assuming I understand what you're
trying to do, I don't think your proposed solution is necessarily all that
bad.
Personally, I find the factory pattern a bit awkward regardless. So
equivocating as to whether having a variable-length parameter list is
inelegant seems pointless. :) Regardless, whatever you think of the
elegance of the factory pattern, it's there to solve a specific issue and
if it makes sense for the same factory to instantiate different types that
don't use the same parameter lists for their constructors, I don't think
it's a bad idea to make the factory flexible enough to built the
constructor parameter lists dynamically.
I'm not sure you need a Dictionary though. Why not just insist that the
parameter list passed in needs to match the parameter list required for
the constructor? Then you can just use the same parameter list.
Finally, I'll note that the fact that you have these different classes
that don't use the same parameter list for construction _might_ be a hint
that using the same factory to create instances of those classes isn't the
right approach. Again, without more specifics it's hard to say. But it's
something to consider.
Pete
jonathan.broderick@gmail.com - 13 Mar 2008 01:09 GMT
On Mar 12, 4:51 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> >> So pass in the superset of objects you need to pass to the
> >> constructors, and
[quoted text clipped - 27 lines]
>
> Pete
Pete,
Thanks I think I'm using factories incorrectly in this case. I'm not
creating a family of related objects that are depending upon each
other, I'm pretty much just creating single or multiple instances of
one type of object.
Where I was getting confused is that I have multiple subclasses that I
may need to create but I want to have a single factory call create
them all for me. Its confusing, i know but I think i'm settled now.
Thanks!