 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Attila Feher Guest
|
Posted: Tue Aug 26, 2003 6:40 pm Post subject: Re: Creating Custom Class Factory objects |
|
|
AH wrote:
| Quote: | Hello everyone,
Traditionally, class factories create objects by their default
constructors. I want my class factory to create an object with its
overloaded constructor which may take 1 or 2 arguments. I dont want
to create overloaded methods in the class factory because I think
that will screw up the design. Besides, generic class factories
should'nt have to worry about that detail ( I
think ). I wonder if this is a design limitation of Factory pattern,
which only creates objects by their default constructors?
|
IMHO if you want to create objects of the same class(es) differing in the
constructor parameters you might want to use the Prototype pattern instead.
In that case you would copy-construct the classes from existing ones.
--
Attila aka WW
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Siemel Naran Guest
|
Posted: Thu Aug 28, 2003 3:10 pm Post subject: Re: Creating Custom Class Factory objects |
|
|
"AH" <decent4u (AT) yahoo (DOT) com> wrote in message
| Quote: | Traditionally, class factories create objects by their default
constructors.
I want my class factory to create an object with its overloaded
constructor
which may take 1 or 2 arguments. I dont want to create overloaded methods
in
the class factory because I think that will screw up the design. Besides,
generic class factories should'nt have to worry about that detail ( I
think ). I wonder if this is a design limitation of Factory pattern, which
only creates objects by their default constructors?
|
What do you mean by "I dont want to create overloaded methods in the class
factory because I think that will screw up the design"?
The basic factory idea is a map<string, fptr> where string is the name of
the class, and fptr is a pointer to a function that takes no arguments and
returns an auto_ptr<Object>.
Modify that by making fptr a function that takes one argument.
Further, you could have several maps; first one fptr takes one argument,
second one fptr takes two arguments, etc. Or you could have one map, and
instead of fptr a struct of fptr.
--
+++++++++++
Siemel Naran
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|