Prototype
Prototype design pattern suggest to create a clone of a prototype rather than using new
keyword and deep-copy all values to a clonned instance.
Example - Simple Prototype
In order to implement prototype patern, we can simply implement Clonable interface from Java.
Then we can clone human cells like this.
Example - Define own prototype interface
We can create our own interface that will define how a prototype should be copied into a new class.
Then we can use it as follows and we can exclude casting Object into a specific type.
Last updated
Was this helpful?