From the course: Design Patterns: Creational

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Leverage existing objects

Leverage existing objects

From the course: Design Patterns: Creational

Start my 1-month free trial

Leverage existing objects

- [Instructor] Remember the Factory Method Pattern? - In this pattern, we determine which concrete object instance we create, by our choice of Concrete Factory. In the Factory Method pattern, we have a parallel hierarchy of classes. The Factory Hierarchy, and the Product Hierarchy. These two Hierarchy's mirror one another, because each Factory produces a different product. Now compare this with Prototype. With Prototype we have no need for a parallel hierarchy because the type of object instance we get, is determined by the type of object we clone. This can be decided at run time, based on state. Prototype is particularity helpful when we're creating objects that are complex, or expensive to create new. We have an existing object we can leverage, so by copying that existing object, we may be able to create new objects more efficiently and hide some of the set up complexity from the client. The main benefit of the prototype…

Contents