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 ¶
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 (*Radio) CheckElectronics ¶
func (r *Radio) CheckElectronics()
CheckElectronics inspects and repairs the internal electronics of the Radio.
func (*Radio) Disassemble ¶
func (r *Radio) Disassemble()
Disassemble disassembles the Radio for maintenance.
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.