golang-design-pattern/prototype.go at master - GitHub

文章推薦指數: 80 %
投票人數:10人

设计模式Golang实现-《研磨设计模式》读书笔记. Contribute to senghoo/golang-design-pattern development by creating an account on GitHub. Skiptocontent {{message}} senghoo / golang-design-pattern Public Notifications Star 5.8k Fork 1.5k Code Issues 0 Pullrequests 0 Actions Projects 0 Wiki Security Insights More Code Issues Pullrequests Actions Projects Wiki Security Insights Permalink master Branches Tags Couldnotloadbranches Nothingtoshow Loading {{refName}} default Couldnotloadtags Nothingtoshow {{refName}} default Loading golang-design-pattern/07_prototype/prototype.go / Jumpto Cloneable Function PrototypeManager Function NewPrototypeManager Function Get Method Set Method Gotofile Gotofile T Gotoline L Gotodefinition R Copypath Copypermalink     Cannotretrievecontributorsatthistime 24lines(19sloc) 501Bytes Raw Blame OpenwithDesktop Viewraw Viewblame ThisfilecontainsbidirectionalUnicodetextthatmaybeinterpretedorcompileddifferentlythanwhatappearsbelow.Toreview,openthefileinaneditorthatrevealshiddenUnicodecharacters. LearnmoreaboutbidirectionalUnicodecharacters Showhiddencharacters packageprototype //Cloneable是原型对象需要实现的接口 typeCloneableinterface{ Clone()Cloneable } typePrototypeManagerstruct{ prototypesmap[string]Cloneable } funcNewPrototypeManager()*PrototypeManager{ return&PrototypeManager{ prototypes:make(map[string]Cloneable), } } func(p*PrototypeManager)Get(namestring)Cloneable{ returnp.prototypes[name].Clone() } func(p*PrototypeManager)Set(namestring,prototypeCloneable){ p.prototypes[name]=prototype } Copylines Copypermalink Viewgitblame Referenceinnewissue Go Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?