Prototype Design Pattern in Python

Publié le: 13 avril 2019
sur la chaîne: SBCODE
4,294
62

Prototype Design Pattern Article :   / prototype-design-pattern-in-python  

Documentation : https://sbcode.net/python/prototype/

Design Patterns In Python Book : https://www.amazon.com/dp/B08XLJ8Z2J

Prototype design pattern is good for when creating new objects may require more resources than you want to use or have available, versus just making a new copy in memory.
Eg, A file you've downloaded from a server may be large, but
since it is already in memory, you could just clone it, and
work on the new copy independently of the original.

In the prototype patterns interface, you create a static clone method that should be implemented by all classes that use the interface.
How the clone method is implemented in the concrete class is up to you.
You will need to decide whether a shallow or deep copy is required.
A shallow copy, copies and creates new references 1 level deep,
A deep copy, copies and creates new references for all levels.
In Python you have mutable objects such as Lists, Dictionaries,
Sets and any custom Objects you have created. A shallow copy,
will create new copies of the objects with new references in memory, but the underlying data will point to the same location as the original copy. Be sure to test your implementation that
the copy method you use works as expected.

(Book) Sometimes you just want to switch off your computer and read from a book. So, all GoF patterns are discussed in my Design Patterns In Python book
https://www.amazon.com/dp/B08XLJ8Z2J : ASIN B08XLJ8Z2J


Sur cette page du site, vous pouvez voir la vidéo en ligne Prototype Design Pattern in Python durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur SBCODE 13 avril 2019, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 4,294 fois et il a aimé 62 téléspectateurs. Bon visionnage!