April 2017
Beginner to intermediate
394 pages
9h 16m
English
We have seen a few examples of how M5Component derived classes use the Prototype pattern. We will look at a few more important ones a little later, but for now let's look at how the M5Object class uses these Clone methods, and how the M5Object itself is cloned. Recall that the M5Object also had a Clone method. Even though this class isn't part of a hierarchy, it can still use the concept of the Prototype pattern to create cloneable instances. Here is the Clone method of the M5Object:
//M5Object.h class M5Object//Everything is the same as before { public: M5Object* Clone(void) const; }; //M5Object.cpp M5Object* M5Object::Clone(void) const { //create new object M5Object* pClone = new M5Object(m_type); //copy the internal ...Read now
Unlock full access