observer

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 2 Imported by: 0

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

func Run

func Run()

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 NewTvShow

func NewTvShow(title string) *TvShow

NewTvShow creates the new TV show.

func (*TvShow) Broadcast

func (t *TvShow) Broadcast(message string)

Broadcast sends a message to all broadcasters subscribed to this TV show.

func (*TvShow) Notify

func (t *TvShow) Notify(data any)

Notify implements the Observable interface by publishing updates to all subscribed broadcasters.

func (*TvShow) Subscribe

func (t *TvShow) Subscribe(listener Observer)

Subscribe adds a broadcaster to the list of subscribers for this TV show.

func (*TvShow) Unsubscribe

func (t *TvShow) Unsubscribe(listener Observer)

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

func NewTvStation(name string, frequency float32) *TvStation

NewTvStation creates the new TV station.

func (*TvStation) Update

func (t *TvStation) Update(data any)

Update implements the callback function for the external publishers (TV shows).

Jump to

Keyboard shortcuts

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