In this section of the course we're going to take a look at the prototype design pattern and the prototype
design pattern is all about object copying.
So we're going to delve deep into the replication of objects.
Now what is the motivation for using the prototype.
Well it just so happens that complicated objects like cars or iPhones for example they're not really
designed from scratch.
If you think that anytime a factory wants to make a new model of a car they just do it from scratch.
Well you'd be mistaken.
They take an existing design of a car and they change it.
They improve it somehow.
And essentially they reiterate existing designs making them better making them more palatable to the
consumer.
And the prototype design pattern is exactly the same approach in software engineering.
So essentially the prototype is an existing object which can be partially or fully constructed.
So you've already designed something you've already defined for example a very complicated type you've
initialized it maybe use the builder to initialize it and then you simply want to make variations on
it.
So in order to make variations what you need to do is you need to make a copy of the prototype and then
customize it and then when a copy is also sometimes called cloning.
But what we really need is we need something called deep copy deep copy is a situation where you're
copying not just the object but you're copying all of your objects references by making new objects
which replicate the state of those references.
And you're doing it recursively so you need to make a complete copy of the object so that changing this
object doesn't affect the object it just copied.
And we have to make the cloning convenience so we have to provide an API like for example a factory
to make the cloning of existing objects a convenient affair.
So the prototype is quite simply a partially or fully initialized object that you make a copy of.
And then you subsequently use for your own benefit.