Chapter 18
- The prototype pattern helps us create objects that are based on an existing object (or prototype) via cloning. This can easily be done in Python using the
copy
function. - Objects in a database need to be duplicated many times, depending on the application and its users. This may be an expensive operation without prototypes.
- The singleton pattern is helpful when we want to implement a class that should only have one instance. This is useful, for example, when we'd like to maintain the global state of a Python program.
- The singleton pattern may be used to control concurrent access to a shared resource, preventing many concurrency-based bugs and errors.