template_method

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 template_method implements the Template Method design pattern. The Maintainer interface defines the Template Method, implemented by the concrete MaintenanceTechnician type. This type defines the abstract sequence of steps for maintaining various devices. All devices implement the DeviceOperator interface, which declares the set of operations expected by the Template Method. This allows polymorphic execution of the maintenance process across different device types (e.g., Radio, Television) while keeping the overall algorithm structure fixed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run()

Types

type DeviceOperator

type DeviceOperator interface {
	Disassemble()
	Assemble()
	CheckElectronics()
	Clean()
	Run() bool
}

DeviceOperator declares the common interface for the devices that could be maintained.

type Maintainer

type Maintainer interface {
	Maintain(d DeviceOperator)
}

Maintainer defines the Template Method for performing maintenance on a device.

type MaintenanceTechnician

type MaintenanceTechnician struct{}

MaintenanceTechnician is a concrete Maintainer that performs maintenance using the Maintain Template Method.

func (*MaintenanceTechnician) Maintain

func (m *MaintenanceTechnician) Maintain(d DeviceOperator)

Maintain defines the template method for maintaining a device. It outlines the general algorithm for maintenance, while the specific behavior of each step depends on the concrete DeviceOperator implementation.

type Radio

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

Radio represents a concrete device that implements the DeviceOperator interface, allowing it to be serviced through the maintenance process.

func NewRadio

func NewRadio(owner string, complexity byte) *Radio

NewRadio creates the new Radio with the specific owner and maintenance complexity.

func (*Radio) Assemble

func (r *Radio) Assemble()

Assemble assembles the Radio after maintenance.

func (*Radio) CheckElectronics

func (r *Radio) CheckElectronics()

CheckElectronics inspects and repairs the internal electronics of the Radio.

func (*Radio) Clean

func (r *Radio) Clean()

Clean cleans the Radio's interior and components.

func (*Radio) Disassemble

func (r *Radio) Disassemble()

Disassemble disassembles the Radio for maintenance.

func (*Radio) Run

func (r *Radio) Run() bool

Run tests whether the Radio is operational.

type Television

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

Television represents a concrete device that implements the DeviceOperator interface, allowing it to be serviced through the maintenance process.

func NewTelevision

func NewTelevision(name string, workingStatus bool) *Television

NewTelevision creates the new Television with the specific name in predefined working state.

func (*Television) Assemble

func (t *Television) Assemble()

Assemble assembles the Television after maintenance.

func (*Television) CheckElectronics

func (t *Television) CheckElectronics()

CheckElectronics inspects and repairs the internal electronics of the Television.

func (*Television) Clean

func (t *Television) Clean()

Clean cleans the Television's interior and components.

func (*Television) Disassemble

func (t *Television) Disassemble()

Disassemble disassembles the Television for maintenance.

func (*Television) Run

func (t *Television) Run() bool

Run tests whether the Television is operational.

Jump to

Keyboard shortcuts

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