Observer pattern in Go language - Stack Overflow
文章推薦指數: 80 %
The Go way to implement the Observer design pattern - Stack ... Home Public Questions Tags Users Collectives ExploreCollectives FindaJob Jobs Companies Teams StackOverflowforTeams –Collaborateandshareknowledgewithaprivategroup. CreateafreeTeam WhatisTeams? Teams CreatefreeTeam CollectivesonStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore ObserverpatterninGolanguage AskQuestion Asked 11years,3monthsago Active 1monthago Viewed 8ktimes 16 8 Thisproblemisprettycommon:anobjectshouldnotifyallitssubscriberswhensomeeventoccurs.InC++wemayuseboost::signalsorsomethingelse.ButhowtodothisinGolanguage?Itwouldbenicetoseesomeworkingcodeexamplewhereacoupleofobjectsaresubscribedtoapublisherandprocessnotifications. Thanks goobserver-pattern Share Follow editedDec25'18at23:16 FedirRYKHTIK 9,38666goldbadges5353silverbadges6565bronzebadges askedSep17'10at8:29 StasStas 10.9k66goldbadges3737silverbadges5555bronzebadges Addacomment | 2Answers 2 Active Oldest Votes 20 ThisisactuallyprettysimpleinGo.Usechannels.Thisisthekindofthingthey'remadefor. typePublishstruct{ listeners[]chan*Msg } typeSubscriberstruct{ Channelchan*Msg } func(p*Publisher)Sub(cchan*Msg){ p.appendListener(c) } func(p*Publisher)Pub(m*Msg){ for_,c:=rangep.listeners{ c
延伸文章資訊
- 1Observer pattern in Go language - Stack Overflow
The Go way to implement the Observer design pattern - Stack ...
- 2Observer Design Pattern in Go (Golang)
Observer Design Pattern is a behavioral design pattern. This pattern allows an instance (called s...
- 3Reacting to File Changes Using the Observer Design Pattern ...
To illustrate the observer pattern in Go, we are going to watch for changes in a local folder. Ev...
- 4Observer Design Pattern in Golang with an Example
Observer Design Pattern is a software design pattern that lets you define a subscription mechanis...
- 5Observer Pattern In Golang - Medium
Observer Pattern In Golang · The What · subscriber and the website publishes notifications only f...