package
2.0.4
Repository: https://github.com/yuzp1996/studygolang.git
Documentation: pkg.go.dev

# README

策略模式

定义

定义了算法族,分别封装起来,让他们之间可以相互替换,这种模式让算法的变化独立于使用算法的客户

启示

  • 学会分开变化和不会变化的部分,找出应用中可能需要变化之处,把他们独立处理,不要和那些不需要变化的代码混在一起
  • 多用组合 少用继承

处理方式思路

  • 我们知道Duck中的fly() 和 quack() 会随着鸭子的不同而改变,为了把这两个行为从Duck类中分开,我们将把他们从Duck类中取出来,建立一组新类来代表每个行为
  • 我们应该在鸭子类中包含 设定行为的方法,这样就会在 运行时 动态 的 改变 不同鸭子 的飞行行为
  • 从现在开始,鸭子的行为将被放在分开的类中,此类专门提供某行为接口的实现,这样鸭子类就不需要知道行为的实现细节

其他

  • 良好的 Object–Oriented 设计需要满足 可复用,可扩充,可维护 三个特性
  • 我们常把系统中会变化的部分抽出来封装
  • 封装变化 多用组合少用继承 针对接口编程不针对实现编程

# Functions

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author