bigwolftime / gitmentCommentsPlugin

0 stars 0 forks source link

策略模式 #32

Open bigwolftime opened 3 years ago

bigwolftime commented 3 years ago

https://index1024.gitee.io/xblog/strategy-design-pattern/

一. 引入

在项目开发的过程中, 遇到过这样的需求: 设计一个”拆盲盒”的活动, 用户可以通过消耗抽奖次数进行抽奖, 奖品池中有不同的奖励, 例如: 头像框, 账户零钱, 额外抽奖次数等, 抽到对应的奖励后自动执行入账.

那么在入账的逻辑中, 可能会有这样的代码:

public void reward(reward reward) {

if (