What's the difference between Prototype design pattern and copy constructor in C++

Viewed 3917

I am trying to understand when I should use Prototype design pattern. Here is example of Prototype as I understand it:

class Prototype
{
public:
    virtual Prototype* clone() = 0;
...
};

class ConcretePrototype : public Prototype
{
public:
    Prototype* clone() override { ... }
};

// Usage:
ConcretePrototype proto;
auto protPtr = proto.clone();

Where is a question: Why this better than:

class Obj
{
public:
    Obj();

    Obj(const Obj&);
    Obj& operator = (const Obj& other);
};

Obj o;
Obj o2 = o;

So when should I actually use Prototype?

2 Answers
Related