Documentation
¶
Overview ¶
Package observer implements the Observer design pattern. Observers are defined by the Observer interface, and publishers (subjects) implement the Observable interface. TvShow is a concrete implementation of Observable that can broadcast TV programs to its subscribers. TvStation is a concrete implementation of Observer that reacts to updates through the Update callback function while subscribed to one or more TvShows.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Broadcasting ¶
type Broadcasting interface {
Observable
Broadcast(message string)
}
Broadcasting defines the common interface for all broadcasting programs and shows.
type Observable ¶
type Observable interface {
Subscribe(listener Observer)
Unsubscribe(listener Observer)
Notify(data any)
}
Observable defines the interface for broadcasts subscriptions.
type Observer ¶
type Observer interface {
Update(data any)
}
Observer defines the interface for all broadcasts observers.
type TvShow ¶
type TvShow struct {
// contains filtered or unexported fields
}
TvShow represents a single broadcastable TV show.
func (*TvShow) Broadcast ¶
Broadcast sends a message to all broadcasters subscribed to this TV show.
func (*TvShow) Notify ¶
Notify implements the Observable interface by publishing updates to all subscribed broadcasters.
func (*TvShow) Subscribe ¶
Subscribe adds a broadcaster to the list of subscribers for this TV show.
func (*TvShow) Unsubscribe ¶
Unsubscribe allows to unsubscribe broadcaster from the TV show.
type TvStation ¶
type TvStation struct {
// contains filtered or unexported fields
}
TvStation represents the TV channel broadcaster, that could be subscribed to the specific TV shows.
func NewTvStation ¶
NewTvStation creates the new TV station.