chainofresponsibility

package
v0.0.0-...-d9f233c Latest Latest
Warning

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

Go to latest
Published: May 5, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Chain Of Responsibility 职责链模式:

使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系。
将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止

个人想法:MFC的消息队列机制

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcreteHandlerA

type ConcreteHandlerA struct {
	Handler
}

具体处理结构体,这里简单处理int类型的请求,判断是否在[1-10]之间,是:处理,否:交给successor处理

func NewConcreteHandlerA

func NewConcreteHandlerA() *ConcreteHandlerA

func (*ConcreteHandlerA) HandleRequest

func (c *ConcreteHandlerA) HandleRequest(req int) int

type ConcreteHandlerB

type ConcreteHandlerB struct {
	Handler
}

具体处理结构体,这里简单处理int类型的请求,判断是否在[11-20]之间,是:处理,否:交给successor处理

func NewConcreteHandlerB

func NewConcreteHandlerB() *ConcreteHandlerB

func (*ConcreteHandlerB) HandleRequest

func (c *ConcreteHandlerB) HandleRequest(req int) int

type Handler

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

实现处理请求的接口的基本结构体类型

func (*Handler) SetSuccessor

func (h *Handler) SetSuccessor(i IHandler)

type IHandler

type IHandler interface {
	SetSuccessor(IHandler)
	HandleRequest(int) int
}

处理请求接口

Jump to

Keyboard shortcuts

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