-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
264 changed files
with
2,114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>design_pattern</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package js.com.adapter; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class Adaptee { | ||
public void specificRequest(){ | ||
System.out.println("特殊请求"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package js.com.adapter; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class Adapter extends Target{ | ||
private Adaptee adaptee = new Adaptee(); | ||
|
||
@Override | ||
public void request() { | ||
adaptee.specificRequest(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package js.com.adapter; | ||
|
||
/** | ||
* 适配器模式 | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class Client { | ||
public static void main(String[] args) { | ||
Target target = new Adapter(); | ||
target.request(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package js.com.adapter; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class Target { | ||
public void request(){ | ||
System.out.println("普通请求"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package js.com.bridge; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class Abstraction { | ||
protected Implementor implementor; | ||
|
||
public void setImplementor(Implementor implementor) { | ||
this.implementor = implementor; | ||
} | ||
|
||
public void operation(){ | ||
implementor.operation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package js.com.bridge; | ||
|
||
/** | ||
* 桥接模式 | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class Client { | ||
public static void main(String[] args) { | ||
Abstraction ab = new RefinedAbstraction(); | ||
ab.setImplementor(new ConcreteImplementorA()); | ||
ab.operation(); | ||
|
||
ab.setImplementor(new ConcreteImplementorB()); | ||
ab.operation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package js.com.bridge; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class ConcreteImplementorA implements Implementor { | ||
@Override | ||
public void operation() { | ||
System.out.println("具体实现A的方法执行"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package js.com.bridge; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class ConcreteImplementorB implements Implementor { | ||
@Override | ||
public void operation() { | ||
System.out.println("具体实现B的方法执行"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package js.com.bridge; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public interface Implementor { | ||
public void operation(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package js.com.bridge; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class RefinedAbstraction extends Abstraction { | ||
@Override | ||
public void operation() { | ||
implementor.operation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package js.com.build; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/22. | ||
*/ | ||
public abstract class Builder { | ||
|
||
public abstract void builderPartA(); | ||
|
||
public abstract void builderPartB(); | ||
|
||
public abstract Product getResult(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package js.com.build; | ||
|
||
/** | ||
* 创建模式,和工厂模式不同是这货用来创建复杂模型 | ||
* 具体的Builder引用了Product,再让Director指挥builder去执行builder的创建方法。 | ||
* 然后再自行返回Product | ||
* Created by Administrator on 2015/4/22. | ||
*/ | ||
public class Client { | ||
public static void main(String[] args) { | ||
Director director = new Director(); | ||
|
||
Builder b1 = new ConcreteBuilder1(); | ||
Builder b2 = new ConcreteBuilder2(); | ||
|
||
director.construct(b1);; | ||
Product p1 = b1.getResult(); | ||
p1.show(); | ||
|
||
director.construct(b2); | ||
Product p2 = b2.getResult(); | ||
p2.show(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package js.com.build; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/22. | ||
*/ | ||
public class ConcreteBuilder1 extends Builder { | ||
|
||
private Product product = new Product(); | ||
|
||
@Override | ||
public void builderPartA() { | ||
product.add("部件A"); | ||
} | ||
|
||
@Override | ||
public void builderPartB() { | ||
product.add("部件B"); | ||
} | ||
|
||
@Override | ||
public Product getResult() { | ||
return product; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package js.com.build; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/22. | ||
*/ | ||
public class ConcreteBuilder2 extends Builder { | ||
|
||
private Product product = new Product(); | ||
|
||
@Override | ||
public void builderPartA() { | ||
product.add("部件X"); | ||
} | ||
|
||
@Override | ||
public void builderPartB() { | ||
product.add("部件Y"); | ||
} | ||
|
||
@Override | ||
public Product getResult() { | ||
return product; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package js.com.build; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/22. | ||
*/ | ||
public class Director { | ||
public void construct(Builder builder){ | ||
builder.builderPartA(); | ||
builder.builderPartB(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package js.com.build; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/22. | ||
*/ | ||
public class Product { | ||
List<String> parts = new ArrayList(); | ||
public void add(String part){ | ||
parts.add(part); | ||
} | ||
|
||
public void show(){ | ||
System.out.println("产品创建"); | ||
for (int i = 0; i < parts.size(); i++) { | ||
System.out.println(parts.get(i)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package js.com.chain_of_responsibility; | ||
|
||
/** | ||
* 责任链模式 | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class Client { | ||
public static void main(String[] args) { | ||
Handler h1 = new ConcreteHandle1(); | ||
Handler h2 = new ConcreteHandle2(); | ||
Handler h3 = new ConcreteHandle3(); | ||
h1.setSuccessor(h2); | ||
h2.setSuccessor(h3); | ||
|
||
int[] requests = new int[]{2, 5, 12, 7, 28, 23, 18, 11}; | ||
|
||
for(int i=0; i<requests.length; i++){ | ||
h1.handleRequest(requests[i]); | ||
} | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package js.com.chain_of_responsibility; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class ConcreteHandle1 extends Handler { | ||
|
||
@Override | ||
public void handleRequest(int request) { | ||
if(request >= 0 && request < 10){ | ||
System.out.println(this.getClass().getSimpleName() + " handle " + request); | ||
}else if (successor != null){ | ||
successor.handleRequest(request); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package js.com.chain_of_responsibility; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class ConcreteHandle2 extends Handler { | ||
@Override | ||
public void handleRequest(int request) { | ||
if(request >= 10 && request < 20){ | ||
System.out.println(this.getClass().getSimpleName() + " handle " + request); | ||
}else if (successor != null){ | ||
successor.handleRequest(request); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package js.com.chain_of_responsibility; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class ConcreteHandle3 extends Handler{ | ||
@Override | ||
public void handleRequest(int request) { | ||
if(request >= 20 && request < 30){ | ||
System.out.println(this.getClass().getSimpleName() + " handle " + request); | ||
}else if (successor != null){ | ||
successor.handleRequest(request); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package js.com.chain_of_responsibility; | ||
|
||
/** | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public abstract class Handler { | ||
|
||
protected Handler successor; | ||
|
||
public void setSuccessor(Handler successor){ | ||
this.successor = successor; | ||
} | ||
|
||
public abstract void handleRequest(int request); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package js.com.command; | ||
|
||
/** | ||
* 命令模式 | ||
* Created by Administrator on 2015/4/23. | ||
*/ | ||
public class Client { | ||
public static void main(String[] args) { | ||
Receiver r = new Receiver(); | ||
Command c = new ConcreteCommand(r); | ||
Invoker i = new Invoker(); | ||
i.setCommand(c); | ||
i.executeCommand(); | ||
} | ||
} |
Oops, something went wrong.