设计模式
look4liming
这个作者很懒,什么都没留下…
展开
-
设计模式:单例模式(Singleton Pattern、懒汉)
/** * 单例模式。 * @author Bright Lee */public class Singleton { private static volatile Singleton instance; private Singleton() { System.out.println("构造方法被调用了,当前时间戳是:" + System.currentTi...原创 2018-11-29 15:34:22 · 207 阅读 · 0 评论 -
设计模式:状态模式(State Pattern)
/** * 状态模式。 * @author Bright Lee */public class StatePattern { public static void main(String[] args) { Context context = new Context(); context.request(); context.request(); }}cla...原创 2019-01-08 17:41:48 · 150 阅读 · 0 评论 -
设计模式:组合模式(Composite Pattern)
import java.util.ArrayList;import java.util.LinkedHashMap;import java.util.List;/** * 组合模式。 * @author Bright Lee */public class CompositePattern { public static void main(String[] args) { ...原创 2019-01-08 15:56:16 · 150 阅读 · 0 评论 -
设计模式:迭代器模式(Iterator Pattern)
/** * 迭代器模式。 * @author Bright Lee */public class IteratorPattern { public static void main(String[] args) { MenuItem[] menuItems = new MenuItem[] { new MenuItem("红烧肉"), new MenuItem("鱼...原创 2019-01-08 10:44:50 · 138 阅读 · 0 评论 -
设计模式:适配器模式(Adaptor Pattern)
/** * 适配器模式将一个类的接口转换成另一个类的接口, * 让原本不兼容的类之间可以合作。 * @author Bright Lee */public class AdaptorPattern { public static void main(String[] args) { // 被适配者: Adaptee adaptee = new Adaptee(); //...原创 2018-12-17 15:08:14 · 205 阅读 · 0 评论 -
设计模式:模板方法模式(Template Method Pattern)
/** * 模板方法模式。 * 模板方法模式在一个方法中定义算法的骨架,而将一些步骤延迟到子类中。 * 模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤。 * @author Bright Lee */public class TemplateMethodPattern { public static void main(String[] args) { ...原创 2018-12-21 14:24:11 · 131 阅读 · 0 评论 -
设计模式:命令模式(Command Pattern)
/** * 命令模式。 * @author Bright Lee */public class CommandPattern { public static void main(String[] args) { Receiver receiver = new Receiver(); Command cmd001 = new OnCommand(receiver); C...原创 2018-12-14 16:49:13 · 166 阅读 · 0 评论 -
设计模式:抽象工厂模式(Abstract Factory Pattern)
/** * 抽象工厂模式。<br/> * 抽象工厂模式提供一个接口,用于创建相关或依赖对象的家族,而不需要明确指定具体类。 * @author Bright Lee */public class AbstractFactoryPattern { public static void main(String[] args) { AbstractFactory facto...原创 2018-12-14 14:25:23 · 211 阅读 · 0 评论 -
设计模式:工厂方法模式(Factory Method Pattern)
/** * 工厂方法模式。 * @author Bright Lee */public class FactoryMethodPattern { public static void main(String[] args) { Creator creator = null; creator = new Creator001(); creator.create();...原创 2018-12-07 16:40:17 · 180 阅读 · 0 评论 -
设计模式:观察者模式(Observer Pattern、JDK实现)
import java.util.Observable;import java.util.Observer;/** * 观察者模式(JDK实现)。 * @author Bright Lee */public class JdkObserverPattern { public static void main(String[] args) { AnimalKeeper su...原创 2018-11-30 16:26:39 · 228 阅读 · 0 评论 -
设计模式:观察者模式(Observer Pattern)
import java.util.ArrayList;import java.util.List;/** * 观察者模式。 * @author Bright Lee */public class ObserverPattern { public static void main(String[] args) { Subject subject = new AnimalKe...原创 2018-11-30 15:49:55 · 207 阅读 · 0 评论 -
设计模式:装饰者模式(Decorator Pattern)
设计模式:装饰者模式(Decorator Pattern)/** * 装饰者模式。 * @author Bright Lee */public class DecoratorPattern { public static void main(String[] args) { Component component = new ConcreteComponent(); comp...原创 2018-12-04 11:51:33 · 226 阅读 · 1 评论 -
设计模式:行为模式(Behavior Pattern)
/** * 行为模式。 * @author Bright Lee */public class BehaviorPattern { public static void main(String[] args) { Animal animal = null; animal = new Dog(); animal.setCallBehavior(new WangWan...原创 2018-11-29 17:03:04 · 560 阅读 · 2 评论 -
设计模式:单例模式(Singleton Pattern、饿汉)
/** * 单例模式。 * @author Bright Lee */public class Singleton { private static final Singleton instance = new Singleton(); private Singleton() { System.out.println("构造方法被调用了,当前时间戳是:" + ...原创 2018-11-29 15:51:13 · 202 阅读 · 0 评论 -
设计模式:策略模式(Strategy Pattern)
/** * 策略模式。 * @author Bright Lee */public class StrategyPattern { public static void main(String[] args) { int num1 = 1; int num2 = 2; int result = 0; Algorithm algorithm = null; ...原创 2019-01-08 18:12:22 · 112 阅读 · 0 评论