Prototype: Use a prototype instance to specify the type of the object to be created, and copy the prototype to create a new object.
The prototype is essentiallyClone object, So inObject initialization operations are complex, which can greatly reduce time consumption and improve performance.Because "you do not need to re-initialize the object, but dynamically obtain the object runtime status ".
Shortest copy (Shallow copy): The object field is copied, but the object referenced by the field is not copied. The Copied object and the source object only share the same name, but share the same object.
Deep copy (Deep copy): The object referenced by fields in the object instance is also copied.
# Encoding = UTF-8 ## by Panda # prototype mode import copydef printinfo (Info): Print Unicode (Info, 'utf-8 '). encode ('gbk') # copy Interface Class icloneable: def shallowclone (Self): Return copy. copy (Self) def deepclone (Self): Return copy. deepcopy (Self) # Work Experience class workexperience (icloneable): workdata = "" Company = "" pass # resume class resume (icloneable ): name = "" Sex = 'unknown 'age = 0 work = none def _ init _ (self, name, work = workexperience (): Self. name = Name self. work = work; def setpersoninfo (self, Sex, Age): Self. sex = sex self. age = age def setworkexperience (self, workdata, company): Self. work. workdata = workdata self. work. company = company def display (Self): printinfo ('% s, % s, % d' % (self. name, self. sex, self. age) printinfo ('% s, % s' % (self. work. workdata, self. work. company) def clientui (): A = resume ('daybird '). setpersoninfo ('male', 29). setworkexperience ("1998-2000", "XX Company") # copy B =. shallowclone () B. setworkexperience ("2000-2006", "YY Company") # Deep copy c =. deepclone () C. setworkexperience ("2006-2009", "ZZ company") B. display (). display () C. display () returnif _ name _ = '_ main _': clientui ();
Class diagram: