golang-design-pattern/prototype.go at master - GitHub
文章推薦指數: 80 %
设计模式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.
延伸文章資訊
- 1Design pattern in Golang — Prototype | by Surya Reddy
Design pattern in Golang — Prototype ... In a real-life scenario, a complex object (e.g. Car, Pho...
- 2Prototype Pattern in Go (Golang)
It is a creational design pattern that lets you create copies of objects. In this pattern, the re...
- 3what is the difference between pool and prototype patterns?
I've just read the chapter on Creational patterns in the book Design Patterns in golang. These ar...
- 4一起幫忙解決難題,拯救IT 人的一天
【Day 27】Design Patterns with Go II:Prototype, Singleton, Facade ... 程式碼都來自golang-design-pattern,註...
- 5Prototype Design Pattern inGolang - FAUN Publication
The Prototype pattern instructs the copying objects themselves to make copies. It introduces a co...