April 2017
Beginner to intermediate
394 pages
9h 16m
English
The Prototype pattern is simple. It involves giving an object for which you might want to copy a Clone method, and letting the object know about the details of how to perform the clone. The actual name of the method isn't important. Clone is just one common example. This is most powerful when used with object hierarchies in which you want to copy an object, but don't know the type of derived object you might be holding. Simply add a Clone method to the interface of a hierarchy and have the derived classes each implement the method. Let's look at a simple example to start off:

In the following code, we have our interface ...
Read now
Unlock full access