File tree Expand file tree Collapse file tree 1 file changed +18
-16
lines changed
Expand file tree Collapse file tree 1 file changed +18
-16
lines changed Original file line number Diff line number Diff line change 1- from copy import deepcopy
1+ import copy
22
33
44class Prototype :
55def __init__ (self ):
6- self ._objs = {}
6+ self ._objects = {}
77
8- def registerObject (self , name , obj ):
9- """
10- register an object.
11- """
12- self ._objs [name ] = obj
8+ def register_object (self , name , obj ):
9+ """Register an object"""
10+ self ._objects [name ] = obj
1311
14- def unregisterObject (self , name ):
15- """unregister an object"""
16- del self ._objs [name ]
12+ def unregister_object (self , name ):
13+ """Unregister an object"""
14+ del self ._objects [name ]
1715
1816def clone (self , name , ** attr ):
19- """clone a registered object and add/replace attr """
20- obj = deepcopy (self ._objs [ name ] )
17+ """Clone a registered object and update inner attributes dictionary """
18+ obj = copy . deepcopy (self ._objects . get ( name ) )
2119obj .__dict__ .update (attr )
2220return obj
2321
2422
25- if __name__ == '__main__' :
23+ def main () :
2624class A :
27- pass
25+ pass
2826
2927a = A ()
3028prototype = Prototype ()
31- prototype .registerObject ( "a" , a )
32- b = prototype .clone ("a" , a = 1 , b = 2 , c = 3 )
29+ prototype .register_object ( 'a' , a )
30+ b = prototype .clone ('a' , a = 1 , b = 2 , c = 3 )
3331
3432print (a )
3533print (b .a , b .b , b .c )
34+
35+
36+ if __name__ == '__main__' :
37+ main ()
You can’t perform that action at this time.
0 commit comments