factory

package
v1.80.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 2 Imported by: 0

README

This has absolutely nothing to do with the bullshit "factory pattern" popularized by
the book "Design Patterns: Elements of Reusable Object-Oriented Software", by
Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John (1995), Addison-Wesley,
ISBN 0-201-63361-2. Nor is it the https://www.google.com/search?q=oop+factory+pattern.
It has nothing to do with Gang of Four, or Gang of Five, or any other Gang of Bullshit.

Instead, it specifically implements this:
https://www.google.com/search?q=factory+production+line&udm=2
https://en.wikipedia.org/wiki/Production_line
https://en.wikipedia.org/wiki/Assembly_line

This is also close conceptually to the https://www.google.com/search?q=state+machine,
the main difference is that here all states (stations) are grouped in lines. Or you
can think of lines as states, and have more granularoty inside, and persistize the
line names, as state IDs, i.e., the persistization granularity would be lines.

Principle of operation:

        factory {:}
            line-A [s1 s2 s3 s4]
            line-B [s1 s2 s3 s4]
            line-C [s1 s2 s3]

	- when we finish last station of line, and there's no intent to jump to another line - stop;
	- we can stop explicitly;
	- can jump to another line from any station;

	Lines are like labels in a program, kind of, if all stations were one single list. This setup
	simplifies management of it and is simpler conceptually.

What can be used for:

    - For pipelines/sequences of processing operations;

    - For business logic state machines, including persistent ones;

Unrelated links:
    https://refactoring.guru/design-patterns/history
    https://perl.plover.com/yak/design/

Documentation

Index

Constants

View Source
const (
	LineType_Undef = iota
	LineType_Object
	LineType_Func
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory[PRODUCT any] struct {
	Hook_PreLine      func(pprec *ProductProgressRecord[PRODUCT])
	Hook_AfterLine    func(pprec *ProductProgressRecord[PRODUCT])
	Hook_PreStation   func(pprec *ProductProgressRecord[PRODUCT])
	Hook_AfterStation func(pprec *ProductProgressRecord[PRODUCT])
	// contains filtered or unexported fields
}

This has absolutely nothing to do with the bullshit "factory pattern" popularized by the book "Design Patterns: Elements of Reusable Object-Oriented Software", by Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John (1995), Addison-Wesley, ISBN 0-201-63361-2. Nor is it the https://www.google.com/search?q=oop+factory+pattern. It has nothing to do with Gang of Four, or Gang of Five, or any other Gang of Bullshit. Instead, it specifically implements this: https://www.google.com/search?q=factory+production+line&udm=2 https://en.wikipedia.org/wiki/Production_line https://en.wikipedia.org/wiki/Assembly_line The Factory is thread-safe for operation, but thread-unsafe for modification.

func NewFactory

func NewFactory[PRODUCT any]() *Factory[PRODUCT]

func (*Factory[PRODUCT]) AddLineOfFuncs

func (f *Factory[PRODUCT]) AddLineOfFuncs(name string) *Line[PRODUCT]

func (*Factory[PRODUCT]) AddLineOfObjects

func (f *Factory[PRODUCT]) AddLineOfObjects(name string) *Line[PRODUCT]

func (*Factory[PRODUCT]) Line

func (f *Factory[PRODUCT]) Line(name string) (line *Line[PRODUCT])

func (*Factory[PRODUCT]) ProcessFull

func (f *Factory[PRODUCT]) ProcessFull(pprec *ProductProgressRecord[PRODUCT])

func (*Factory[PRODUCT]) ProcessOneLine

func (f *Factory[PRODUCT]) ProcessOneLine(pprec *ProductProgressRecord[PRODUCT])

To be used in a user-code managed loop, e.g. when each per-line progress gets persistized. Alternatively, consider using ProcessFull().

type IStation

type IStation[PRODUCT any] interface {
	Do(*ProductProgressRecord[PRODUCT])
}

type Line

type Line[PRODUCT any] struct {
	// contains filtered or unexported fields
}

func (*Line[PRODUCT]) AddStationAsFunc

func (line *Line[PRODUCT]) AddStationAsFunc(s StationFunc[PRODUCT]) *Line[PRODUCT]

func (*Line[PRODUCT]) AddStationAsObject

func (line *Line[PRODUCT]) AddStationAsObject(s IStation[PRODUCT]) *Line[PRODUCT]

func (*Line[PRODUCT]) EndOfLine

func (line *Line[PRODUCT]) EndOfLine()

syntax sugar

type ProductProgressRecord

type ProductProgressRecord[PRODUCT any] struct {
	Product         PRODUCT
	CurrentPosition struct {
		Line    string
		Station int
	}
	FullStopNow bool
	JumpToLine  string
}

See https://en.wikipedia.org/wiki/Medical_record

func NewProductProgressRecord

func NewProductProgressRecord[PRODUCT any](product PRODUCT, lineName string) *ProductProgressRecord[PRODUCT]

type StationFunc

type StationFunc[PRODUCT any] func(*ProductProgressRecord[PRODUCT])

func (StationFunc[PRODUCT]) Do

func (sf StationFunc[PRODUCT]) Do(pr *ProductProgressRecord[PRODUCT])

Jump to

Keyboard shortcuts

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