Re: Trouble with factory pattern
From: Alf P. Steinbach (alfps_at_start.no)
Date: Thu, 16 Oct 2003 14:52:50 GMT
On Thu, 16 Oct 2003 16:22:04 +0200, Boogie El Aceitoso <firstname.lastname@example.org> wrote:
>I'd like to have a function factory that returns objects of a class hierarchy.
>What's the best way to deal with the fact that different subclasses will have
>different constructor arguments?
If different subclasses _require_ different constructor arguments this
should be reflected in the factory functions' argument lists. It's not
a C++ question but a design question. If there is a requirement then the
client code will have to supply those arguments, in one form or another.
>How do you keep the factory interface as clean as possible? O:-)
That depends on how you're planning to use that, as well as personal
preference (what _you_, and/or your coworkers, regard as "clean").