-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoredItemPrototype.py
More file actions
37 lines (24 loc) · 951 Bytes
/
Copy pathStoredItemPrototype.py
File metadata and controls
37 lines (24 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import abc
from flask_app import StoredBook, StoredUser
from common_logger import log
class StoredItemPrototypeInterface(metaclass=abc.ABCMeta):
@abc.abstractmethod
def clone(self):
pass
@abc.abstractclassmethod
def __init__(self, item_to_clone):
pass
class StoredUserPrototype(StoredItemPrototypeInterface):
def __init__(self, item_to_clone):
self.item_to_clone = item_to_clone
def clone(self):
cloned = StoredUser(username=self.item_to_clone.name)
log('New StoredUser instance derived from simulation prototype %s', cloned)
return cloned
class StoredBookPrototype(StoredItemPrototypeInterface):
def __init__(self, item_to_clone):
self.item_to_clone = item_to_clone
def clone(self):
cloned = StoredBook(title=self.item_to_clone.title)
log('New StoredBook instance derived from simulation prototype %s', cloned)
return cloned