factory2

package
v0.0.0-...-9e1c66b Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Human

type Human interface {
	Eat()
	Play()
}

简单工厂的模式的话就不需要这个接口了 定义人类接口

type HumanFactory

type HumanFactory struct {
}

func (*HumanFactory) CreateWhite

func (factory *HumanFactory) CreateWhite() Human

func (*HumanFactory) CreateYellow

func (factory *HumanFactory) CreateYellow() Human

type HumanFactoryInf

type HumanFactoryInf interface {
	CreateWhite() Human
	CreateYellow() Human
}

缺点:当需要增加创建black时则代码改动很大 优点:可以控制创建产品的关系,我们可以将CreatWhite和CreatYellow内置,然后对外提供Create限制CreatWhite和CreatYellow关系

Jump to

Keyboard shortcuts

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