builder

package
v0.0.0-...-e059a18 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 1 Imported by: 0

README

创建者模式

重点分块创造,返回创建者接口 演示一个造车的例子,并稍微增加一点链式创建的能力

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CarProto

type CarProto struct {
	Wheel     int
	Engine    string
	MaxSpeed  int
	BrandName string
}

CarProto 车的原型

func (*CarProto) Brand

func (c *CarProto) Brand() string

Brand 车品牌

func (*CarProto) Brief

func (c *CarProto) Brief()

Brief 简介

func (*CarProto) Speed

func (c *CarProto) Speed() int

Speed 最大车速

type CarStudio

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

CarStudio 打算通过成立造车实验室进行造车

func (*CarStudio) Brand

func (c *CarStudio) Brand(brand string) ICarBuilder

Brand of car

func (*CarStudio) Build

func (c *CarStudio) Build() ICar

Build return a car

func (*CarStudio) Engine

func (c *CarStudio) Engine(engine string) ICarBuilder

Engine of car

func (*CarStudio) Speed

func (c *CarStudio) Speed(max int) ICarBuilder

Speed of car

func (*CarStudio) Wheel

func (c *CarStudio) Wheel(wheel int) ICarBuilder

Wheel of car

type ICar

type ICar interface {
	Speed() int
	Brand() string
	Brief()
}

ICar 汽车,我们要造车了 ICar 车具有以下能力

type ICarBuilder

type ICarBuilder interface {
	Wheel(wheel int) ICarBuilder
	Engine(engine string) ICarBuilder
	Speed(max int) ICarBuilder
	Brand(brand string) ICarBuilder
	Build() ICar
}

ICarBuilder 造一辆车需要具有的部件

func NewCarStudio

func NewCarStudio() ICarBuilder

NewCarStudio 造车工作室

Jump to

Keyboard shortcuts

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