chain_of_responsibility

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

Documentation

Overview

Package chain_of_responsibility implements the Chain Of Responsibility design pattern. Meals are prepared by executing a sequence of cooking steps, each represented as a process in a chain. Every process performs a specific action and delegates to the next step by calling its Handle() method. After the final step, a printable receipt is generated to represent the completed meal.

Index

Constants

View Source
const (
	Wiener byte = iota
	Frankfurter
	Bratwurst
	Soy
)

Sausage type enums

Variables

This section is empty.

Functions

func Run

func Run()

Types

type AddBun

type AddBun struct {
	CookingStep
	// contains filtered or unexported fields
}

AddBun is the cooking process that adds the bun in the specific place of the meal.

func (*AddBun) Handle

func (ab *AddBun) Handle() bool

Handle handles the cooking step.

type AddPatty

type AddPatty struct {
	CookingStep
}

AddPatty is the cooking process that adds the patty to the meal.

func (*AddPatty) Handle

func (ap *AddPatty) Handle() bool

Handle handles the cooking step.

type AddSauce

type AddSauce struct {
	CookingStep
}

AddSauce is the cooking process that adds one of the random sauce to the meal.

func (*AddSauce) Handle

func (a *AddSauce) Handle() bool

Handle handles the cooking step.

type AddSausage

type AddSausage struct {
	CookingStep
	// contains filtered or unexported fields
}

AddSausage is the cooking process that adds the sausage of the specific type to the meal.

func (*AddSausage) Handle

func (a *AddSausage) Handle() bool

Handle handles the cooking step.

type AddVeggies

type AddVeggies struct {
	CookingStep
}

AddVeggies is the cooking process that adds 2 random veggies to the meal.

func (*AddVeggies) Handle

func (av *AddVeggies) Handle() bool

Handle handles the cooking step.

type Chainable

type Chainable interface {
	Nestable
	Handle() bool
	// contains filtered or unexported methods
}

Chainable defines the interface for a processing step in the chain of responsibility. Each step processes part of a meal and delegates to the next step, if any.

type Combinable

type Combinable interface {
	fmt.Stringer
	Layerable
	// contains filtered or unexported methods
}

Combinable declares the interface of a completed meal that can accumulate layers and could be rendered as a string.

type CookingStep

type CookingStep struct {
	Meal Combinable
	// contains filtered or unexported fields
}

CookingStep is the abstract struct that implements the Addable interface and encapsulates the reference to the meal that is cooking and the next step in chain.

func (*CookingStep) AddNext

func (c *CookingStep) AddNext(nextStep Chainable) Chainable

AddNext allows to add the next chainable abstraction to the chain.

type Layerable

type Layerable interface {
	AddLayer(string)
}

Layerable defines how ingredients or modifications are added to a meal.

type Meal

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

Meal represents the meal that is cooked through the chain of responsibility.

func NewMeal

func NewMeal(title string) *Meal

NewMeal is the constructor of the new meal that will be cooked.

func (*Meal) AddLayer

func (m *Meal) AddLayer(layer string)

AddLayer adds the layer to the meal.

func (*Meal) String

func (m *Meal) String() string

String returns human readable form of the cooked meal.

type Nestable

type Nestable interface {
	AddNext(step Chainable) Chainable
	// contains filtered or unexported methods
}

Nestable provides accessors for chaining steps together.

Jump to

Keyboard shortcuts

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