Skip to content

Commit 87c59f2

Browse files
author
GiantsLoveDeathMetal
committed
Add description to prototype pattern
1 parent 6ff38db commit 87c59f2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

creational/prototype.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5+
*What is this pattern about?
6+
This patterns aims to reduce the number of classes required by an
7+
application. Instead of relying on subclasses it creates objects by
8+
copying a prototypical instance at run-time.
9+
10+
This is useful as it make it easier to derive new kinds of objects,
11+
when instances of the class have only a few different combinations of
12+
state, and when instantiation is expensive.
13+
14+
*What does this example do?
15+
When the number of prototypes in an application can vary, it can be
16+
useful to keep a Dispatcher (aka, Registry or Manager). This allows
17+
clients to query the Dispatcher for a prototype before cloning a new
18+
instance.
19+
20+
Below provides an example of such Dispatcher, which contains three
21+
copies of the prototype: 'default', 'objecta' and 'objectb'.
22+
523
*TL;DR80
624
Creates new object instances by cloning prototype.
725
"""

0 commit comments

Comments
 (0)