mediator

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: 1 Imported by: 0

Documentation

Overview

Package mediator implements the Mediator design pattern. The Aircraft interface represents the colleague entities that can request landing or takeoff operations, always via the mediator. The TrafficControl interface represents the mediator that coordinates aircraft operations. It ensures aircraft interact only indirectly, through centralized traffic organization. ControlTower is the concrete mediator, while Plane and Helicopter are concrete colleagues.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run()

Types

type Aircraft

type Aircraft interface {
	RequestTakeOff() bool
	RequestLanding() bool
	CompleteOperation()
	ReceiveControlMessage(string)
}

Aircraft is the common interface for all colleagues.

type ControlTower

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

ControlTower is the mediator that implements TrafficControl interface.

func NewControlTower

func NewControlTower() *ControlTower

NewControlTower is the ControlTower constructor.

func (*ControlTower) NotifyOperationEnding

func (c *ControlTower) NotifyOperationEnding(ac Aircraft)

NotifyOperationEnding implements the traffic control feedback for the operation ending attempt from the aircraft.

func (*ControlTower) RequestCraftLanding

func (c *ControlTower) RequestCraftLanding(ac Aircraft) bool

RequestCraftLanding checks the runway, puts aircraft in the queue and notifies if landing can be executed.

func (*ControlTower) RequestCraftTakeoff

func (c *ControlTower) RequestCraftTakeoff(ac Aircraft) bool

RequestCraftTakeoff checks the runway, puts aircraft in the queue and notifies if taking off can be executed.

type Helicopter

type Helicopter struct {
	ID string
	// contains filtered or unexported fields
}

Helicopter is a colleague that implements Airctaft interface.

func NewHelicopter

func NewHelicopter(id string, ct TrafficControl) *Helicopter

NewHelicopter is the Helicopter constructor, that receives the identifier and traffic control mediator as params.

func (*Helicopter) CompleteOperation

func (h *Helicopter) CompleteOperation()

CompleteOperation tries to finish the previously requested operation.

func (*Helicopter) ReceiveControlMessage

func (h *Helicopter) ReceiveControlMessage(message string)

ReceiveControlMessage logs the individual feedback from the mediator.

func (*Helicopter) RequestLanding

func (h *Helicopter) RequestLanding() bool

RequestLanding notifies mediator on the landing necessity.

func (*Helicopter) RequestTakeOff

func (h *Helicopter) RequestTakeOff() bool

RequestTakeOff notifies mediator on the taking off necessity.

type Plane

type Plane struct {
	ID string
	// contains filtered or unexported fields
}

Plane is a colleague that implements Airctaft interface.

func NewPlane

func NewPlane(id string, ct TrafficControl) *Plane

NewPlane is the Plane constructor, that receives the identifier and traffic control mediator as params.

func (*Plane) CompleteOperation

func (p *Plane) CompleteOperation()

CompleteOperation tries to finish the previously requested operation.

func (*Plane) ReceiveControlMessage

func (p *Plane) ReceiveControlMessage(message string)

ReceiveControlMessage logs the individual feedback from the mediator.

func (*Plane) RequestLanding

func (p *Plane) RequestLanding() bool

RequestLanding notifies mediator on the landing necessity.

func (*Plane) RequestTakeOff

func (p *Plane) RequestTakeOff() bool

RequestTakeOff notifies mediator on the taking off necessity.

type TrafficControl

type TrafficControl interface {
	RequestCraftLanding(Aircraft) bool
	RequestCraftTakeoff(Aircraft) bool
	NotifyOperationEnding(Aircraft)
}

TrafficControl is the common interface for the mediators.

Jump to

Keyboard shortcuts

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