creator

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DEFAULT_MESSAGE = Message{/* contains filtered or unexported fields */}

Functions

func Main

func Main()

Types

type Builder

type Builder interface {
	Part1()
	Part2()
	Part3()
}

Builder 是生成器接口

type Builder1

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

func (*Builder1) GetResult

func (b *Builder1) GetResult() string

func (*Builder1) Part1

func (b *Builder1) Part1()

func (*Builder1) Part2

func (b *Builder1) Part2()

func (*Builder1) Part3

func (b *Builder1) Part3()

type Builder2

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

func (*Builder2) GetResult

func (b *Builder2) GetResult() int

func (*Builder2) Part1

func (b *Builder2) Part1()

func (*Builder2) Part2

func (b *Builder2) Part2()

func (*Builder2) Part3

func (b *Builder2) Part3()

type Director

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

func NewDirector

func NewDirector(builder Builder) *Director

NewDirector ...

func (*Director) Construct

func (d *Director) Construct()

Construct Product

type Message

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

func New

func New(id, phone int, name, addr string) Message

func NewByOption

func NewByOption(opts ...Option) Message

func NewByOptionWithoutID

func NewByOptionWithoutID(id int, opts ...Option) Message

func (Message) String

func (msg Message) String()

type MinusOperator

type MinusOperator struct {
	*OperatorBase
}

MinusOperator Operator 的实际减法实现

func (MinusOperator) Result

func (o MinusOperator) Result() int

Result 获取结果

type MinusOperatorFactory

type MinusOperatorFactory struct{}

MinusOperatorFactory 是 MinusOperator 的工厂类

func (MinusOperatorFactory) Create

func (MinusOperatorFactory) Create() Operator

type Operator

type Operator interface {
	SetA(int)
	SetB(int)
	Result() int
}

Operator 是被封装的实际类接口

type OperatorBase

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

OperatorBase 是Operator 接口实现的基类,封装公用方法

func (*OperatorBase) SetA

func (o *OperatorBase) SetA(a int)

SetA 设置 A

func (*OperatorBase) SetB

func (o *OperatorBase) SetB(b int)

SetB 设置 B

type OperatorFactory

type OperatorFactory interface {
	Create() Operator
}

OperatorFactory 是工厂接口

type Option

type Option func(msg *Message)

func WithAddress

func WithAddress(addr string) Option

func WithID

func WithID(id int) Option

func WithName

func WithName(name string) Option

func WithPhone

func WithPhone(phone int) Option

type PlusOperator

type PlusOperator struct {
	*OperatorBase
}

PlusOperator Operator 的实际加法实现

func (PlusOperator) Result

func (o PlusOperator) Result() int

Result 获取结果

type PlusOperatorFactory

type PlusOperatorFactory struct{}

PlusOperatorFactory 是 PlusOperator 的工厂类

func (PlusOperatorFactory) Create

func (PlusOperatorFactory) Create() Operator

type Singleton

type Singleton interface {
	// contains filtered or unexported methods
}

Singleton 是单例模式接口,导出的 通过该接口可以避免 GetInstance 返回一个包私有类型的指针

func GetInstance

func GetInstance() Singleton

GetInstance 用于获取单例模式对象

Jump to

Keyboard shortcuts

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