observer

package
v0.0.0-...-404d2c9 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClassMonitor

type ClassMonitor struct {
	// contains filtered or unexported fields
}

ClassMonitor stands for observer

func (*ClassMonitor) AddListener

func (c *ClassMonitor) AddListener(listener StudentListener)

AddListener add StudentListener into list

func (*ClassMonitor) Notify

func (c *ClassMonitor) Notify()

Notify send notification to all listeners

func (*ClassMonitor) RemoveListener

func (c *ClassMonitor) RemoveListener(listener StudentListener)

RemoveListener remove StudentListener from list

type Event

type Event struct {
	Owner    Listener
	Receiver Listener
	Notifier Notifier
	Message  string
}

Event of concrete

type Hero

type Hero struct {
	Name  string
	Party string
}

Hero stands for concrete Listener

func (*Hero) Fight

func (h *Hero) Fight(receiver Listener, n Notifier)

Fight metheod of the hero

func (*Hero) GetName

func (h *Hero) GetName() string

GetName return the name of the hero

func (*Hero) GetParty

func (h *Hero) GetParty() string

GetParty return the party of the hero

func (*Hero) OnBeFighted

func (h *Hero) OnBeFighted(event *Event)

OnBeFighted metheod of the hero

func (*Hero) Title

func (h *Hero) Title() string

Title of Hero

type Informer

type Informer struct {
	// contains filtered or unexported fields
}

Informer stands for concrete Listener

func (*Informer) Attach

func (in *Informer) Attach(listener Listener)

Attach add listener into Informer list

func (*Informer) Detach

func (in *Informer) Detach(listener Listener)

Detach remove listener from Informer list

func (*Informer) Notify

func (in *Informer) Notify(event *Event)

Notify send notification to each Listener

type Listener

type Listener interface {
	Title() string
	GetName() string
	GetParty() string
	OnBeFighted(event *Event)
}

Listener of abstract Event

type Notifier

type Notifier interface {
	Attach(listener Listener)
	Detach(listener Listener)
	Notify(event *Event)
}

Notifier of abstract Event

type Student

type Student struct {
	Name  string
	Event string
}

Student of concrete

func NewStudent

func NewStudent(name, event string) *Student

NewStudent return a new Student instance

func (*Student) Doing

func (s *Student) Doing()

Doing of student

func (*Student) OnTeacherComming

func (s *Student) OnTeacherComming()

OnTeacherComming of student

type StudentListener

type StudentListener interface {
	OnTeacherComming()
}

StudentListener of abstract Listener

type StudentNotifier

type StudentNotifier interface {
	Notify()
	AddListener(l StudentListener)
	RemoveListener(l StudentListener)
}

StudentNotifier of abstract Notifier

Jump to

Keyboard shortcuts

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