
TypeScript 4 Design Patterns and Best Practices
By :

The next creational design pattern that you will study is the Prototype. This pattern helps abstract the object creation process. Let's explore in detail what we mean.
A Prototype is a kind of object that takes its initial state and properties out of existing objects. The main idea is to avoid having to manually create an object and assign properties to it from another object.
Using a Prototype pattern, you can use objects that implement the Prototype interface. Instead of creating a new object by calling the new
operator, you instead follow a divergent path. You construct objects that adhere to the Prototype interface, which has a single method, clone()
. When called, it will clone the existing instance of the object and its internal properties. You can avoid duplicating the logic of creating a new object and assigning common functionality. You will now learn what the ideal circumstances are for using this pattern.