mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-26 21:56:02 +03:00
18 lines
399 B
Go
18 lines
399 B
Go
package observer
|
|
|
|
func ExampleObserver() {
|
|
subject := NewSubject()
|
|
reader1 := NewReader("reader1")
|
|
reader2 := NewReader("reader2")
|
|
reader3 := NewReader("reader3")
|
|
subject.Attach(reader1)
|
|
subject.Attach(reader2)
|
|
subject.Attach(reader3)
|
|
|
|
subject.UpdateContext("observer mode")
|
|
// Output:
|
|
// reader1 receive observer mode
|
|
// reader2 receive observer mode
|
|
// reader3 receive observer mode
|
|
}
|