strategy

package
v0.0.0-...-eb36113 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0, MIT Imports: 1 Imported by: 0

README

策略模式

定义一系列算法,让这些算法在运行时可以互换,使得分离算法,符合开闭原则。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bank

type Bank struct{}

func (*Bank) Pay

func (*Bank) Pay(ctx *PaymentContext)

type Cash

type Cash struct{}

func (*Cash) Pay

func (*Cash) Pay(ctx *PaymentContext)

type Payment

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

func NewPayment

func NewPayment(name, cardid string, money int, strategy PaymentStrategy) *Payment

func (*Payment) Pay

func (p *Payment) Pay()

type PaymentContext

type PaymentContext struct {
	Name, CardID string
	Money        int
}

type PaymentStrategy

type PaymentStrategy interface {
	Pay(*PaymentContext)
}

Jump to

Keyboard shortcuts

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