随笔分类 -  设计模式

摘要:代码实现 /** * 源发器类 * @author bzhx * 2017年3月15日 */ public class Emp { private String ename; private int age; private double salary; //备忘操作,并返回备忘录对象 public 阅读全文
posted @ 2017-09-05 13:37 皈依之路 阅读(130) 评论(0) 推荐(0)
摘要:代码实现1 public interface Observer { void update(Subject subject); } public class ObserverA implements Observer{ private int myState; //myState需要跟目标对象的st 阅读全文
posted @ 2017-09-05 13:26 皈依之路 阅读(180) 评论(0) 推荐(0)
摘要:代码实现 public interface State { void handle(); } /** * 空闲状态 * @author bzhx * 2017年3月15日 */ public class FreeState implements State{ @Override public voi 阅读全文
posted @ 2017-09-05 13:11 皈依之路 阅读(197) 评论(0) 推荐(0)
摘要:代码实现 public abstract class BankTemplateMethod { //具体方法 public void takeNumber(){ System.out.println("取号排队"); } public abstract void transact(); //办理具体 阅读全文
posted @ 2017-09-05 13:06 皈依之路 阅读(178) 评论(0) 推荐(0)
摘要:代码实现 public interface Strategy { public double getPrice(double standardPrice); } public class NewCustomerFewStrategy implements Strategy{ @Override pu 阅读全文
posted @ 2017-09-05 13:01 皈依之路 阅读(134) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2017-09-05 12:54 皈依之路 阅读(101) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2017-09-05 12:53 皈依之路 阅读(141) 评论(0) 推荐(0)
摘要:介绍 角色 使用场景 代码实现 public interface Command { //这个方法是一个返回结果为空的方法 //实际项目中,可以根据需求设计多个不同的方法 void execute(); } class ConcreteCommand implements Command{ priv 阅读全文
posted @ 2017-09-05 12:50 皈依之路 阅读(215) 评论(0) 推荐(0)
摘要:代码实现 public interface Mediator { void register(String dname,Department d); void command(String dname); } /* * 同事类接口 */ public interface Department { v 阅读全文
posted @ 2017-09-05 12:01 皈依之路 阅读(190) 评论(0) 推荐(0)
摘要:代码实现 public interface MyIterator { void first(); //将游标指向第一个元素 void next(); //将游标指向下一个元素 boolean hasNext(); //判断是否存在下一个元素 boolean isFirst(); boolean is 阅读全文
posted @ 2017-09-05 11:50 皈依之路 阅读(139) 评论(0) 推荐(0)
摘要:后面我们将学习设计模式里面的行为型模式 代码实现 /** * 抽象类 * @author bzhx * 2017年3月14日 */ public abstract class Leader { protected String name; protected Leader nextLeader; / 阅读全文
posted @ 2017-09-05 11:42 皈依之路 阅读(246) 评论(0) 推荐(0)
摘要:代码实现 1 /** 2 * 享元工厂类 3 * @author bzhx 4 * 2017年3月14日 5 */ 6 public class ChessFlyWeightFactory { 7 //享元池 8 private static Map<String,ChessFlyWeight> m 阅读全文
posted @ 2017-09-04 13:41 皈依之路 阅读(149) 评论(0) 推荐(0)
摘要:代码实现 public interface Bank { void lend(); } class WuHanBank implements Bank{ @Override public void lend() { System.out.println("银行借钱"); } } public int 阅读全文
posted @ 2017-09-04 13:33 皈依之路 阅读(103) 评论(0) 推荐(0)
摘要:代码实现 public interface ICar { void move(); } //具体构件角色(真实对象,被装饰角色) class Car implements ICar{ @Override public void move() { System.out.println("陆地上跑"); 阅读全文
posted @ 2017-09-04 13:29 皈依之路 阅读(153) 评论(0) 推荐(0)
摘要:代码实现 //Component(抽象构件):抽象构件中定义了叶子和容器构件的共同点。比如,有公共的添加删除叶子功能,有显示节点功能。 public abstract class Component { protected String name; public Component(String n 阅读全文
posted @ 2017-09-04 12:30 皈依之路 阅读(175) 评论(0) 推荐(0)
摘要:代码实现 public interface Brand { void sale(); } class Lenovo implements Brand{ @Override public void sale() { System.out.println("销售联想电脑"); } } class Del 阅读全文
posted @ 2017-09-04 12:17 皈依之路 阅读(134) 评论(0) 推荐(0)
摘要:定义与模型 ‘ 应用场景和分类 代码实现 staticProxy public interface Star { /** * 面谈 */ void confer(); /** * 签合同 */ void signContract(); /** * 订票 */ void bookTicket(); / 阅读全文
posted @ 2017-09-04 11:40 皈依之路 阅读(175) 评论(0) 推荐(0)
摘要:从现在开始,将转入设计模式中的结构型模式 定义与角色 工作场景 代码实现 /** * 被适配的类--相当于键盘 * @author bzhx * 2017年3月10日 */ public class Adaptee { public void request(){ System.out.printl 阅读全文
posted @ 2017-09-04 11:18 皈依之路 阅读(182) 评论(0) 推荐(0)
摘要:public class Sheep implements Cloneable,Serializable{ private String sname; private Date birthday; @Override protected Object clone() throws CloneNotS 阅读全文
posted @ 2017-09-02 12:28 皈依之路 阅读(140) 评论(0) 推荐(0)
摘要:本质与使用场景 public interface AirShipBuilder { Engine builderEngine(); OrbitalModule builderOrbitalModule(); EscapeTower builderEscapeTower(); } public cla 阅读全文
posted @ 2017-09-02 11:50 皈依之路 阅读(143) 评论(0) 推荐(0)