This is a creation in Article, where the information may have evolved or changed.
Pattern Features: Use prototype instances to specify the kind of objects that are created, and create new objects by copying those prototypes.
Program examples: From the Resume prototype, generate a new resume, resume class resumes provide Clone () method.
package mainimport ("fmt")type PersonalInfo struct {name stringsex stringage string}type WorkExperience struct {timeArea stringcompany string}type Resume struct {PersonalInfoWorkExperience}func (this *Resume) SetPersonalInfo(name string, sex string, age string) {this.name = namethis.sex = sexthis.age = age}func (this *Resume) SetWorkExperience(timeArea string, company string) {this.timeArea = timeAreathis.company = company}func (this *Resume) Display() {fmt.Println(this.name, this.sex, this.age)fmt.Println("工作经历:", this.timeArea, this.company)}func (this *Resume) Clone() *Resume {resume := *thisreturn &resume}func main() {r1 := &Resume{}r1.SetPersonalInfo("大鸟", "男", "29")r1.SetWorkExperience("1998-2000", "xx公司")r2 := r1.Clone()r2.SetWorkExperience("2001-2006", "yy公司")r3 := r1.Clone()r3.SetPersonalInfo("大鸟", "男", "24")r1.Display()r2.Display()r3.Display()}