You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
508 B

package responsibility_chain
import "strconv"
type Handle interface {
Handle(handleId int) string
}
type handle struct {
name string
next *handle
handleId int
}
func NewHandle(name string, next *handle, handleId int) *handle {
return &handle{name: name, next: next, handleId: handleId}
}
func (h *handle) Handle(handleId int) string {
if h.handleId == handleId {
return h.name + " 操作 " + strconv.Itoa(handleId)
}
if h.next == nil {
return ""
}
return h.next.Handle(handleId)
}