设计模式 decorator_test 实现

2022-07-21 浏览 (1214)

golang 设计模式 decorator_test 代码实现

package decorator

import "fmt"

func ExampleDecorator() {
	var c Component = &ConcreteComponent{}
	c = WarpAddDecorator(c, 10)
	c = WarpMulDecorator(c, 8)
	res := c.Calc()

	fmt.Printf("res %d\n", res)
	// Output:
	// res 80
}

目录

go 设计模式

相关文章

装饰模式

设计模式 decorator 实现

  • 所属分类: 后端技术
  • 本文标签: golang
  • 版权声明: 本文链接 https://seaxiang.com/blog/550056d321aa4f3a83edb861474f26f4