This commit is contained in:
Ilkka Seppälä
2019-12-13 21:09:28 +02:00
parent 0335c61512
commit b2b1ba95eb
127 changed files with 282 additions and 450 deletions

View File

@ -5,9 +5,8 @@ folder: prototype
permalink: /patterns/prototype/
categories: Creational
tags:
- Java
- Gang Of Four
- Difficulty-Beginner
- Instantiation
---
## Intent
@ -68,10 +67,10 @@ System.out.println(cloned.getName()); // Dolly
## Applicability
Use the Prototype pattern when a system should be independent of how its products are created, composed and represented; and
* when the classes to instantiate are specified at run-time, for example, by dynamic loading
* to avoid building a class hierarchy of factories that parallels the class hierarchy of products
* when instances of a class can have one of only a few different combinations of state. It may be more convenient to install a corresponding number of prototypes and clone them rather than instantiating the class manually, each time with the appropriate state
* when object creation is expensive compared to cloning
* When the classes to instantiate are specified at run-time, for example, by dynamic loading
* To avoid building a class hierarchy of factories that parallels the class hierarchy of products
* When instances of a class can have one of only a few different combinations of state. It may be more convenient to install a corresponding number of prototypes and clone them rather than instantiating the class manually, each time with the appropriate state
* When object creation is expensive compared to cloning
## Real world examples