策略设计模式
来源:互联网 发布:防范sql注入攻击的方法 编辑:程序博客网 时间:2024/06/11 00:28
/**
接口应用
*/
class InterfaceAppDemo
{
public static void main(String[] args)
{
Person p = new Person(“小白”);
System.out.println(“——–子宫前————–”);
p.setIsay(new Beforegong());
p.say();
System.out.println(“———子宫后———-“);
p.setIsay(new Aftergong());
p.say();
}
}
//把说话的行为抽象成一个借口
interface Isay
{
public void say();
}
class Beforegong implements Isay
{
public void say()
{
System.out.println(“人家是纯爷们”);
}
}
class Aftergong implements Isay
{
public void say()
{
System.out.println(“人家现在是宫女了”);
}
}
class Person
{//把可变化的行为抽象出来,定义成接口,并提供不同的实现
private String name;//把接口作为类中的一个属性(组合)private Isay isay;public Person(String name){ this.name = name;}public void setIsay(Isay isay){ this.isay = isay;}//这个方法的实现是变化的public void say(){ isay.say();}
}
0 0
- 设计模式-策略模式
- 设计模式:策略模式
- 设计模式-策略模式
- 设计模式 - 策略模式
- 设计模式-策略模式
- 设计模式-----策略模式
- 设计模式 策略模式
- 设计模式-策略模式
- 设计模式-【策略模式】
- 设计模式-----策略模式
- 设计模式-策略模式
- 设计模式--策略模式
- 设计模式- 策略模式
- 设计模式- 策略模式
- 设计模式------策略模式
- 设计模式--策略模式
- 设计模式-策略模式
- 设计模式--策略模式
- JavaScript-DOM
- 函数指针的使用
- macbook上的远程桌面
- Android消息机制
- java设计模式-克隆模式(复制模式)
- 策略设计模式
- Web.xml详解
- 浙大PAT 4-09. 笛卡尔树 (解题思路)
- dubbo+zookeeper服务器配置
- Android面试经验(转载)
- 朴素贝叶斯方法(Naive Bayes)
- 自定义Spark Streaming接收器(Receivers)
- leetcode--最长公共前缀--简单的字符串操作
- android studio for android learning (十九 ) 最新Handler消息传递机制全解