设计模式
设计模式
Reverse train.
这个作者很懒,什么都没留下…
展开
-
代理模式
//抽象角色 public interface Star { void sing(); void sign(); void bookticket(); void money(); void talk(); } //真是角色 public class RealStar implements Star{ @Override publi...原创 2020-03-20 19:23:25 · 210 阅读 · 0 评论 -
装饰模式
装饰模式动态地给一个对象添加一些额外的职责(功能)。它把每个要装饰的功能放在单独的类中,并让这个类包装它所要装饰的对象。 这里省去了ConcreteComponent,Person作为Component,Decorator 作为Decorator装饰类。 TShirts和BigTrouser类作为具体的装饰对象,给Person添加不同的功能。 public class Person { ...原创 2020-03-17 14:27:44 · 129 阅读 · 0 评论 -
策略模式
策略模式(Strategy):它定义了算法家族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户。 本质:分离算法,选择实现。 1.Strategy:定义所有支持的算法(打折算法)的公共接口 public interface Strategy { double getPrice(double price); } 2.封装具体的算法,实现Str...原创 2020-03-13 17:30:12 · 132 阅读 · 0 评论 -
简单工厂模式
实现创建者和调用者的分离。 此处我们设计个程序,输入两个数和运算符号,输出结果。 //运算类 public class Operation { double number01=0; double number02=0; public double getNumber01() { return number01; } public...原创 2020-03-12 13:59:26 · 91 阅读 · 0 评论 -
设计模式
原创 2020-03-12 13:14:40 · 145 阅读 · 0 评论