Design Patterns
谢灵枢
爱编程爱游戏
展开
-
Singleton 单例模式
package com.lonton.designpatterns; public class Singleton { private static final Singleton SINGLETON = new Singleton(); public static Singleton getSingleton() { return SINGLETON; } }转载 2014-08-11 10:23:56 · 500 阅读 · 0 评论 -
Mememto 备忘录模式
package com.lonton.designpatterns; import java.util.List; import java.util.ArrayList; class Life { private String time; private List mememtos = new ArrayList(); public void setTime(String time)转载 2014-08-11 10:42:18 · 929 阅读 · 0 评论 -
Builder 创建者模式
package com.lonton.designpatterns; class Drink { private String size; private String type; public void setSize(String size) { this.size = size; } public void setType(String type) { this.转载 2014-08-11 10:31:55 · 506 阅读 · 0 评论 -
Strategy 策略模式
package com.lonton.designpatterns; interface Strategy { public void processSpeed(int speed); } class NicePolice implements Strategy { @Override public void processSpeed(int speed) { // TODO A转载 2014-08-11 10:45:01 · 552 阅读 · 0 评论 -
Command 命令模式
package com.lonton.designpatterns; import java.util.List; import java.util.ArrayList; //Command Interface interface Command { public void execute(); } class ShutdownCommand implements Command {转载 2014-08-11 10:36:56 · 593 阅读 · 0 评论 -
Factory 工厂模式
package com.lonton.designpatterns; interface Human { public void Talk(); public void Walk(); } class Boy implements Human { @Override public void Talk() { System.out.println("Boy转载 2014-08-11 10:28:01 · 540 阅读 · 0 评论 -
Observer 观察者模式
package com.lonton.designpatterns; import java.util.ArrayList; interface Subject { public void registerObserver(Observer observer); public void removeObserver(Observer observer); public void notif转载 2014-08-11 10:43:31 · 525 阅读 · 0 评论 -
Chain of Responsibility 责任链模式
package com.lonton.designpatterns; abstract class Chain { public static int ONE = 1; public static int TWO = 2; public static int THREE = 3; protected int threshold; protected Chain next; p转载 2014-08-11 10:35:24 · 501 阅读 · 0 评论 -
Prototype 原型模式
package com.lonton.designpatterns; interface Prototype { void setSize(int x); void printSize(); } class A implements Prototype, Cloneable { private int size; public A(int x) { size = x; }转载 2014-08-11 10:33:40 · 791 阅读 · 0 评论 -
State 状态模式
package com.lonton.designpatterns; interface State { public void saySomething(StateContext stateContext); } class Poor implements State { @Override public void saySomething(StateContext sc) {转载 2014-08-11 10:43:50 · 514 阅读 · 0 评论 -
Proxy 代理模式
package com.lonton.designpatterns; interface SluttyWife { public void seduceMen(); public void happyWithMen(); } class HouseWife implements SluttyWife { @Override public void seduceMen() { /转载 2014-08-11 10:42:42 · 1459 阅读 · 0 评论 -
Composite 组合模式
package com.lonton.designpatterns; import java.util.ArrayList; interface Component { public void show(); } class Composite implements Component { ArrayList childComponents = new ArrayList(); p转载 2014-08-11 10:38:09 · 511 阅读 · 0 评论 -
Mediator 中介者模式
package com.lonton.designpatterns; interface IMediator { public void ask(); public void answer(); public void registerA(ColleagueA a); public void registerB(ColleagueB b); } class ConcreteMed转载 2014-08-11 10:40:29 · 725 阅读 · 0 评论 -
Iterator 迭代器模式
package com.lonton.designpatterns; interface Iterator { public boolean hasNext(); public Object next(); } interface Container { public Iterator creaIterator(); } class RecordCollection implement转载 2014-08-11 10:39:19 · 538 阅读 · 0 评论 -
Abstract 抽象工厂模式
package com.lonton.designpatterns; interface CPU { void process(); } interface CPUFactory { CPU produceCPU(); } class AMDCPU implements CPU { @Override public void process() { // TODO Auto-转载 2014-08-11 10:27:50 · 482 阅读 · 0 评论 -
Visitor 访问者模式
package com.lonton.designpatterns; import java.util.ArrayList; interface Visitor { public void visit(City city); public void visit(Museum museum); public void viist(Park park); } class FirstTi转载 2014-08-11 10:46:03 · 557 阅读 · 0 评论