Skip to content

Commit 3db54c4

Browse files
author
laileon
committed
add
1 parent 0b4e992 commit 3db54c4

File tree

1 file changed

+15
-0
lines changed
  • src/com/blankj/custom/desingn_pattern/strategy/example

1 file changed

+15
-0
lines changed

src/com/blankj/custom/desingn_pattern/strategy/example/Client.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
package com.blankj.custom.desingn_pattern.strategy.example;
22

3+
4+
//https://blog.csdn.net/u012124438/article/details/70039943/
5+
//
6+
//策略模式的定义和使用场景
7+
//
8+
// 定义:策略模式定义了一系列的算法,并将每一个算法封装起来,而且使他们可以相互替换,让算法独立于使用它的客户而独立变化。
9+
//
10+
// 分析下定义,策略模式定义和封装了一系列的算法,它们是可以相互替换的,也就是说它们具有共性,而它们的共性就体现在策略接口的行为上,另外为了达到最后一句话的目的,也就是说让算法独立于使用它的客户而独立变化,我们需要让客户端依赖于策略接口。
11+
//
12+
// 策略模式的使用场景:
13+
//
14+
// 1.针对同一类型问题的多种处理方式,仅仅是具体行为有差别时;
15+
// 2.需要安全地封装多种同一类型的操作时;
16+
// 3.出现同一抽象类有多个子类,而又需要使用 if-else 或者 switch-case 来选择具体子类时。
17+
318
public class Client {
419
public static void main(String[] args) {
520
Player player = new Player();

0 commit comments

Comments
 (0)