April 2017
Beginner to intermediate
394 pages
9h 16m
English
As we said, the biggest benefit of using the Prototype pattern is that we can make copies without knowing the type. This means we can make a copy of a function parameter or function return type without caring about the derived class involved. This also means that we can share a pointer with another class or method and we don't need to care if the type is modified.
In the following example, we have a SpawnShape class with the ability to spawn a specific type of shape. By using the Prototype pattern, the class doesn't need to care what type it is spawning. The constructor takes a pointer to some shape and then it just needs to call the Clone method. If the base class pointer is pointing to a Circle, then a circle ...
Read now
Unlock full access