April 2017
Beginner to intermediate
394 pages
9h 16m
English
The Prototype pattern gives us a way to copy a class without knowing the actual type of that class. This is often referred to as a virtual constructor because we can use it to create and copy a derived class while only using a base class pointer or reference. This pattern is most powerful when used with object hierarchies, but it doesn't only need to be used with virtual functions. Another purpose of the Prototype pattern is simply to create a prototypical (or archetypical) instance of an object and to use that to copy from.
Imagine that we are creating a level editor. In the middle of the tool we would have the map of the level. Here we can place tiles, power-ups, enemies, and players. Along the side of the ...
Read now
Unlock full access