C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Creating Custom Class Factory objects

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Attila Feher
Guest





PostPosted: Tue Aug 26, 2003 6:40 pm    Post subject: Re: Creating Custom Class Factory objects Reply with quote



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





PostPosted: Thu Aug 28, 2003 3:10 pm    Post subject: Re: Creating Custom Class Factory objects Reply with quote



"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.