Documentation
¶
Overview ¶
开发模式代码实现包
设计模式 ¶
创建型 C
结构型 J
行为型 X
-AbstractFactory.go : 抽象工厂模式(C) -Adapter.go : 适配器模式(J) -Bridge.go : 桥接模式(J) -Builder.go : 建造者模式(C) -ChainOfResponsibility.go : 责任链模式(X) -Command.go : 命令模式(X) -Composite.go : 组合模式(J) -Decorator.go : 装饰器模式(J) -Facade.go : 外观模式(J) -Factory.go : 工厂模式(C) -Flyweight.go : 享元模式(J) -Interpreter.go : 解释器模式(X) -Iterator.go : 迭代器模式(X) -Mediator.go : 中介者模式(X) -Memento.go : 备忘录模式(X) -Observer.go : 观察者模式(X) -Prototype.go : 原型模式(C) -Proxy.go : 代理模式(J) -Singleton.go : 单例模式(C) -Singleton2.go : 单例模式(C) -State.go : 状态模式(X) -Strategy.go : 策略模式(X) -Template.go : 模板模式(X) -Visitor.go : 访问者模式(X)
Index ¶
- Constants
- func AdapterTest()
- func ChainOfResponsibilityTest()
- func CommandTest()
- func CompositeTest()
- func DecoratorTest()
- func Double(n int) int
- func FacadeTest()
- func FlyweightTest()
- func InterpreterTest()
- func IteratorTest()
- func MediatorTest()
- func MementoTest()
- func ObserverTest()
- func ProxyTest()
- func RunGame(g Game)
- func Singleton2SaySomething()
- func StateTest()
- func StrategyTest()
- func TemplateTest()
- func TestBridge()
- func VisitorTest()
- type ABData
- type AObserver
- type AToB
- type AbsGame
- type AbsScreenEventHandler
- type AbstractFactory
- type AdapterNonToYes
- type AddVisitor
- type AirStrategy
- type AndExpression
- type ArrayContainer
- type ArrayIterator
- type BaseMessageBuilder
- type Beer
- type BikeStrategy
- type BraceMessageBuilderDecorator
- type BrushPen
- type BusStrategy
- type CdnRequest
- type ChatRoom
- type Client
- type Cloneable
- type CmdContext
- type Coder
- type Cola
- type Command
- type CommandHandler
- type Company
- type Container
- type Context
- type Context1
- type Context2
- type ContextPool
- type Cricket
- type DataStruct
- type DbConnect
- type DbConnectPool
- type Department
- type Device
- type Drink
- type Expression
- type Food
- type FootBall
- type FriedChicken
- type Game
- type GetCommand
- type Hamburger
- type HardDisk
- type HardDiskProxy
- type HomeScreenEventHandler
- type IScreenEventHandler
- type Item
- type Iterator
- type Light
- type LightState
- type LiveRequest
- type MaintenancePeople
- type Meal
- type MealBuilder
- type Memento
- type MessageBuilder
- type NonRechargeableA
- type NonRechargeableB
- type NonRechargeableBattery
- type Object
- type Observer
- type OffLightState
- type OnLightState
- type OrExpression
- type PenFactory
- type PencilFactory
- type PostCommand
- type ProductPlanner
- type QuoteMessageBuilderDecorator
- type RechargeableBattery
- type RechargeableBatteryAbstract
- type Request
- type ScreenEvent
- type Singleton
- type Singleton2
- type Storage
- type Strategy
- type SubVisitor
- type Subject
- type TerminalExpression
- type Tester
- type Text
- type User
- type UserScreenEventHandler
- type Visitor
Constants ¶
const ( FOOD = "food" DRINK = "drink" )
Variables ¶
This section is empty.
Functions ¶
func ChainOfResponsibilityTest ¶
func ChainOfResponsibilityTest()
func CommandTest ¶
func CommandTest()
func FacadeTest ¶
func FacadeTest()
func FlyweightTest ¶
func FlyweightTest()
func InterpreterTest ¶
func InterpreterTest()
func IteratorTest ¶
func IteratorTest()
func MediatorTest ¶
func MediatorTest()
func MementoTest ¶
func MementoTest()
func ObserverTest ¶
func ObserverTest()
func Singleton2SaySomething ¶
func Singleton2SaySomething()
func StrategyTest ¶
func StrategyTest()
func TemplateTest ¶
func TemplateTest()
func TestBridge ¶
func TestBridge()
func VisitorTest ¶
func VisitorTest()
Types ¶
type AbsScreenEventHandler ¶
type AbsScreenEventHandler struct {
NextHandler IScreenEventHandler
}
func (*AbsScreenEventHandler) Handle ¶
func (ase *AbsScreenEventHandler) Handle(se *ScreenEvent) bool
func (*AbsScreenEventHandler) SetNextHandler ¶
func (ase *AbsScreenEventHandler) SetNextHandler(ise IScreenEventHandler)
type AdapterNonToYes ¶
type AdapterNonToYes struct {
NonRechargeableBattery
}
适配可充电电池使用接口
func (AdapterNonToYes) Charge ¶
func (AdapterNonToYes) Charge()
type AddVisitor ¶
type AddVisitor struct { }
func (*AddVisitor) Visit ¶
func (av *AddVisitor) Visit(dataS DataStruct)
type AirStrategy ¶
type AirStrategy struct {
Speed float64
}
func (*AirStrategy) Do ¶
func (as *AirStrategy) Do(ab interface{})
type AndExpression ¶
type AndExpression struct { A Expression B Expression }
与
func (*AndExpression) Interpret ¶
func (ae *AndExpression) Interpret(context string) bool
type ArrayContainer ¶
type ArrayContainer struct {
// contains filtered or unexported fields
}
数组集合
func (*ArrayContainer) GetIterator ¶
func (ac *ArrayContainer) GetIterator() Iterator
type ArrayIterator ¶
type ArrayIterator struct {
// contains filtered or unexported fields
}
数组迭代器
func (*ArrayIterator) HasNext ¶
func (ai *ArrayIterator) HasNext() bool
func (*ArrayIterator) Next ¶
func (ai *ArrayIterator) Next() interface{}
type BaseMessageBuilder ¶
type BaseMessageBuilder struct { }
基本信息构造器
func (*BaseMessageBuilder) Build ¶
func (b *BaseMessageBuilder) Build(messages ...string) string
type BikeStrategy ¶
type BikeStrategy struct {
Speed float64
}
func (*BikeStrategy) Do ¶
func (bs *BikeStrategy) Do(ab interface{})
type BraceMessageBuilderDecorator ¶
type BraceMessageBuilderDecorator struct {
Builder MessageBuilder
}
大括号装饰器
func (*BraceMessageBuilderDecorator) Build ¶
func (b *BraceMessageBuilderDecorator) Build(messages ...string) string
type BusStrategy ¶
type BusStrategy struct {
Speed float64
}
func (*BusStrategy) Do ¶
func (bs *BusStrategy) Do(ab interface{})
type CdnRequest ¶
type CdnRequest struct { }
func (*CdnRequest) HttpRequest ¶
func (cdn *CdnRequest) HttpRequest() (*http.Request, error)
type ChatRoom ¶
type ChatRoom struct {
// contains filtered or unexported fields
}
func (*ChatRoom) RegisterUser ¶
type CommandHandler ¶
命令管理者
func (*CommandHandler) Handle ¶
func (ch *CommandHandler) Handle(ctx *CmdContext) (interface{}, error)
处理命令
func (*CommandHandler) Register ¶
func (ch *CommandHandler) Register(cmdType string, cmd Command)
注册命令
type Company ¶
type Company struct { ProductPlanner Coder Tester MaintenancePeople }
公司
拥有产品策划、程序员、测试人员,运维人员 通过公司这个外观对外提供服务, 而不是直接通过某个类型人员对外服务(虽然最终提供服务的也是某个类型的人员)
type ContextPool ¶
原型池
func (*ContextPool) AddContext ¶
func (this *ContextPool) AddContext(key string, val *Context)
func (*ContextPool) GetContext ¶
func (this *ContextPool) GetContext(key string) *Context
type DataStruct ¶
type DataStruct interface {
Accept(Visitor)
}
type DbConnectPool ¶
type DbConnectPool struct {
ConnChan chan *DbConnect
}
数据库连接池
func NewDbConnectPool ¶
func NewDbConnectPool(chanLen int) *DbConnectPool
func (*DbConnectPool) Get ¶
func (dc *DbConnectPool) Get() *DbConnect
func (*DbConnectPool) Put ¶
func (dc *DbConnectPool) Put(conn *DbConnect)
type Department ¶
type Department struct { List map[string]*Department Parent *Department Name string Id string }
func (*Department) Remove ¶
func (this *Department) Remove(id string) (department *Department)
移除子节点
type Expression ¶
type FriedChicken ¶
type FriedChicken struct {
Food
}
炸鸡
func (FriedChicken) Name ¶
func (FriedChicken) Name() string
func (FriedChicken) Price ¶
func (FriedChicken) Price() float32
type GetCommand ¶
type GetCommand struct { }
Get 命令
func (*GetCommand) Do ¶
func (gc *GetCommand) Do(args interface{}) (interface{}, error)
type HardDiskProxy ¶
type HardDiskProxy struct { OpId string // contains filtered or unexported fields }
func (*HardDiskProxy) Read ¶
func (h *HardDiskProxy) Read() ([]byte, error)
func (*HardDiskProxy) Write ¶
func (h *HardDiskProxy) Write(word []byte) error
type HomeScreenEventHandler ¶
type HomeScreenEventHandler struct {
AbsScreenEventHandler
}
func (*HomeScreenEventHandler) Handle ¶
func (hse *HomeScreenEventHandler) Handle(se *ScreenEvent) bool
type IScreenEventHandler ¶
type IScreenEventHandler interface { Handle(*ScreenEvent) bool SetNextHandler(IScreenEventHandler) }
type Light ¶
type Light struct {
State LightState
}
灯
func (*Light) PressSwitch ¶
func (l *Light) PressSwitch()
type LiveRequest ¶
type LiveRequest struct { }
func (*LiveRequest) HttpRequest ¶
func (cdn *LiveRequest) HttpRequest() (*http.Request, error)
type MaintenancePeople ¶
type MaintenancePeople struct { }
func (*MaintenancePeople) Releasing ¶
func (m *MaintenancePeople) Releasing()
type MealBuilder ¶
type MealBuilder struct { }
建造者
func (MealBuilder) MealOne ¶
func (MealBuilder) MealOne() (meal *Meal)
type NonRechargeableA ¶
type NonRechargeableA struct { }
不可充电电池A
func (NonRechargeableA) Use ¶
func (NonRechargeableA) Use()
type NonRechargeableB ¶
type NonRechargeableB struct {
RechargeableBatteryAbstract
}
func (NonRechargeableB) Use ¶
func (NonRechargeableB) Use()
type OffLightState ¶
type OffLightState struct { }
type OnLightState ¶
type OnLightState struct { }
type OrExpression ¶
type OrExpression struct { A Expression B Expression }
或
func (*OrExpression) Interpret ¶
func (oe *OrExpression) Interpret(context string) bool
type PenFactory ¶
type PenFactory struct { }
工厂
func (PenFactory) Produce ¶
func (this PenFactory) Produce(typ string) pen
func (PenFactory) ProduceBrushPen ¶
func (PenFactory) ProduceBrushPen() pen
func (PenFactory) ProducePencil ¶
func (PenFactory) ProducePencil() pen
type PencilFactory ¶
type PencilFactory struct { }
func (PencilFactory) Produce ¶
func (PencilFactory) Produce() pen
type PostCommand ¶
type PostCommand struct { }
post 命令
func (*PostCommand) Do ¶
func (pc *PostCommand) Do(args interface{}) (interface{}, error)
type ProductPlanner ¶
type ProductPlanner struct { }
func (*ProductPlanner) Planing ¶
func (p *ProductPlanner) Planing()
type QuoteMessageBuilderDecorator ¶
type QuoteMessageBuilderDecorator struct {
Builder MessageBuilder
}
引号装饰器
func (*QuoteMessageBuilderDecorator) Build ¶
func (q *QuoteMessageBuilderDecorator) Build(messages ...string) string
type RechargeableBatteryAbstract ¶
type RechargeableBatteryAbstract struct { }
func (RechargeableBatteryAbstract) Charge ¶
func (RechargeableBatteryAbstract) Charge()
func (RechargeableBatteryAbstract) Use ¶
func (RechargeableBatteryAbstract) Use()
type ScreenEvent ¶
type Singleton ¶
type Singleton interface {
SaySomething()
}
func NewSingletonInstance ¶
func NewSingletonInstance() Singleton
type Singleton2 ¶
type Singleton2 interface {
SaySomething()
}
type SubVisitor ¶
type SubVisitor struct { }
func (*SubVisitor) Visit ¶
func (sv *SubVisitor) Visit(dataS DataStruct)
type Subject ¶
type Subject struct {
// contains filtered or unexported fields
}
func (*Subject) NotifyAllObservers ¶
func (s *Subject) NotifyAllObservers()
type TerminalExpression ¶
type TerminalExpression struct {
Word string
}
func (*TerminalExpression) Interpret ¶
func (te *TerminalExpression) Interpret(context string) bool
终结符
type UserScreenEventHandler ¶
type UserScreenEventHandler struct {
AbsScreenEventHandler
}
func (*UserScreenEventHandler) Handle ¶
func (use *UserScreenEventHandler) Handle(se *ScreenEvent) bool
type Visitor ¶
type Visitor interface {
Visit(DataStruct)
}
Source Files
¶
- AbstractFactory.go
- Adapter.go
- Bridge.go
- Builder.go
- ChainOfResponsibility.go
- Command.go
- Composite.go
- Decorator.go
- Facade.go
- Factory.go
- Flyweight.go
- Interpreter.go
- Iterator.go
- Mediator.go
- Memento.go
- Observer.go
- Prototype.go
- Proxy.go
- Singleton.go
- Singleton2.go
- State.go
- Strategy.go
- Template.go
- Visitor.go
- doc.go