Wednesday, August 1, 2018

Creational Design Patterns: Prototype Pattern [Snippet]

The prototype pattern is used to create a copy of an object. This pattern can be really useful, especially when creating an object from scratch. In comparison with the builder, factory, and abstract factory patterns, it does not create an object from scratch — it clones it.
However, with the singleton pattern, it creates multiple copies of an instance whilst the singleton has to ensure that only one will exist.

Imagine the scenario of an object that, which in order to be created, requires a very resource-intensive method. It can be a database query with many joins or even the result of a federated search.



from DZone.com Feed https://ift.tt/2O1zIed

No comments:

Post a Comment