From 87c59f2e56b3302e1e9bbba3732eceb4e53662d2 Mon Sep 17 00:00:00 2001 From: GiantsLoveDeathMetal Date: Sat, 16 Jun 2018 14:00:34 +0100 Subject: [PATCH] Add description to prototype pattern --- creational/prototype.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/creational/prototype.py b/creational/prototype.py index 4e99871d..034cec45 100644 --- a/creational/prototype.py +++ b/creational/prototype.py @@ -2,6 +2,24 @@ # -*- coding: utf-8 -*- """ +*What is this pattern about? +This patterns aims to reduce the number of classes required by an +application. Instead of relying on subclasses it creates objects by +copying a prototypical instance at run-time. + +This is useful as it make it easier to derive new kinds of objects, +when instances of the class have only a few different combinations of +state, and when instantiation is expensive. + +*What does this example do? +When the number of prototypes in an application can vary, it can be +useful to keep a Dispatcher (aka, Registry or Manager). This allows +clients to query the Dispatcher for a prototype before cloning a new +instance. + +Below provides an example of such Dispatcher, which contains three +copies of the prototype: 'default', 'objecta' and 'objectb'. + *TL;DR80 Creates new object instances by cloning prototype. """