variant to prototype...

W

werasm

Hi all,

Traditionally the prototype pattern (cloning) causes
the "cloned" to be copied. Is there an idiom where
the method performing the creation creates the
default type (without cloning). Small example:

template <class T>
struct clonable
{
virtual T* clone() const; //calls new T( *this );
};

template <class T>
struct xxx_able
{
virtual T* xxx() const; //calls new T();
};

Note that this is similar to factory functions, but not
entirely the same as factory functions are aware of
type.

Therefore - I want a prototype that provides the correct
type without cloning. What is the idiom called?

Regards,

Werner
 
V

Victor Bazarov

werasm said:
Traditionally the prototype pattern (cloning) causes
the "cloned" to be copied. Is there an idiom where
the method performing the creation creates the
default type (without cloning). Small example:

template <class T>
struct clonable
{
virtual T* clone() const; //calls new T( *this );
};

template <class T>
struct xxx_able
{
virtual T* xxx() const; //calls new T();
};

Note that this is similar to factory functions, but not
entirely the same as factory functions are aware of
type.

I think you should be able to see a "virtual factory method"
or something like that in the literature.
Therefore - I want a prototype that provides the correct
type without cloning. What is the idiom called?

The "factory method", IIRC.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top