factorymethod

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

README

工厂方法模式

工厂方法模式使用子类的方式延迟生成对象到子类中实现。

不同的工厂对象,返回一个实现了某接口的类型对象,不同的工厂返回不同实现了相同接口的不同对象,在只能使用特定的类简单工厂的基础上,使用的代码和类生成的灵活性大大增加。

Go中的继承关系是使用匿名组合来实现的。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assistant

type Assistant interface {
	Clean(int)
	Speak(string)
	Work() string
}

Assistant 是robot能做的事情

type BasicRobotModel

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

BasicRobotModel 是基本的机器人模型

func (*BasicRobotModel) Clean

func (b *BasicRobotModel) Clean(a int)

Clean 打扫

func (*BasicRobotModel) Speak

func (b *BasicRobotModel) Speak(w string)

Speak 说话

func (*BasicRobotModel) Work

func (b *BasicRobotModel) Work() string

Work main work

type FightingRobot

type FightingRobot struct {
	*BasicRobotModel
}

FightingRobot 实际的战斗机器人

func (FightingRobot) Work

func (f FightingRobot) Work() string

Work for FightingRobot to do some fighting

type FightingRobotFactory

type FightingRobotFactory struct{}

FightingRobotFactory 生产各类军工机器人

func (FightingRobotFactory) Build

Build a robot from FightingRobotFactory

type HomeRobot

type HomeRobot struct {
	*BasicRobotModel
}

HomeRobot 实际的家用机器人

func (HomeRobot) Work

func (h HomeRobot) Work() string

Work robot do some work

type HomeRobotFactory

type HomeRobotFactory struct{}

HomeRobotFactory 生产各类家用机器人

func (HomeRobotFactory) Build

func (HomeRobotFactory) Build() Assistant

Build a robot from HomeRobotFactory

type IRobotFactory

type IRobotFactory interface {
	Build() Assistant
}

IRobotFactory must be implemented by Factory different Factory create different robot

Jump to

Keyboard shortcuts

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