observer

package
v0.0.0-...-7dcde51 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Observer

type Observer interface {
	OnUpdate(msg string)
}
Example
weather := NewSubject()
joe := NewObserver("joe")
weather.attach(joe)
tom := NewObserver("tom")
weather.attach(tom)

weather.notify("today is sunshiny")
fmt.Println("---")

weather.detach(joe)
weather.notify("tomorrow is cloudy")
fmt.Println("---")

weather.detach(tom)
weather.notify("oh my god")
Output:

joe: received "today is sunshiny"
tom: received "today is sunshiny"
---
tom: received "tomorrow is cloudy"
---

func NewObserver

func NewObserver(name string) Observer

type Subject

type Subject interface {
	// contains filtered or unexported methods
}

func NewSubject

func NewSubject() Subject

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL