Skip to content

Commit 19ed151

Browse files
author
gigigigi
committed
update
1 parent f878213 commit 19ed151

1,052 files changed

Lines changed: 26814 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src/dp"/>
4+
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry exported="true" kind="con" path="org.springsource.ide.eclipse.gradle.classpathcontainer"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/build
2+
3+
/.gradle
4+
/.settings
5+
6+
/bin
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>DPModel</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.springsource.ide.eclipse.gradle.core.nature</nature>
16+
<nature>org.eclipse.jdt.core.javanature</nature>
17+
</natures>
18+
</projectDescription>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#DPModel
2+
3+
[设计模式之禅](http://book.douban.com/subject/4260618/)》原书源码,有部分修改。存于此便于以后参考使用。
4+
5+
##六大设计原则(SOLID)
6+
* [单一职责原则(SRP)](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/srp)
7+
* [开闭原则(OCP)](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/ocp)
8+
* [里氏替换原则(LSP)](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/lsp)
9+
* [迪米特法则(LOD)](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/lod)
10+
* [接口隔离原则(ISP)](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/isp)
11+
* [依赖倒置原则(DIP)](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/dip)
12+
13+
14+
##23个设计模式
15+
###1.[单例模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/singleton)
16+
![Alt text](src/dp/com/company/singleton/singleton.gif "单例模式")
17+
18+
###2.[工厂模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/factorys)
19+
![Alt text](src/dp/com/company/factorys/factorys.jpg "工厂模式类图")
20+
21+
###3.[抽象工厂模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/factorya)
22+
![Alt text](src/dp/com/company/factorya/factorya.jpg "抽象工厂模式类图")
23+
24+
###4.[模板模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/template_method)
25+
![Alt text](src/dp/com/company/template_method/template.jpg "模板模式类图")
26+
27+
###5.[建造者模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/builder)
28+
![Alt text](src/dp/com/company/builder/builder.jpg "建造者模式类图")
29+
30+
###6.[代理模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/proxy)
31+
![Alt text](src/dp/com/company/proxy/proxy.jpg "代理模式类图")
32+
33+
###7.[原型模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/prototype)
34+
![Alt text](src/dp/com/company/prototype/prototype.gif "原型模式类图")
35+
36+
###8.[中介模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/mediator)
37+
![Alt text](src/dp/com/company/mediator/mediator.jpg "中介模式类图")
38+
39+
###9.[命令模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/command)
40+
![Alt text](src/dp/com/company/command/command.jpg "命令模式类图")
41+
42+
###10.[责任链模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/chain_of_responsibility)
43+
![Alt text](src/dp/com/company/chain_of_responsibility/chainofresponsibility.jpg "责任链模式类图")
44+
45+
###11.[装饰模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/decorator)
46+
![Alt text](src/dp/com/company/decorator/decorator.jpg "装饰模式类图")
47+
48+
###12.[策略模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/strategy)
49+
![Alt text](src/dp/com/company/strategy/strategy.jpg "策略模式类图")
50+
51+
###13.[适配器模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/adapter)
52+
![Alt text](src/dp/com/company/adapter/adapter.jpg "适配器模式类图")
53+
54+
###14.[迭代器模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/iterator)
55+
![Alt text](src/dp/com/company/iterator/iterator.jpg "迭代器模式类图")
56+
57+
###15.[组合模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/composite)
58+
![Alt text](src/dp/com/company/composite/composite.jpg "组合模式类图")
59+
60+
###16.[观察者模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/observer)
61+
![Alt text](src/dp/com/company/observer/observer.jpg "观察者模式类图")
62+
63+
###17.[门面模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/facade)
64+
![Alt text](src/dp/com/company/facade/facade.gif "门面模式示意图")
65+
66+
###18.[备忘录模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/memento)
67+
![Alt text](src/dp/com/company/memento/memento.jpg "备忘录模式类图")
68+
69+
###19.[访问者模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/visitor)
70+
![Alt text](src/dp/com/company/visitor/visitor.jpg "访问者模式类图")
71+
72+
###20.[状态模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/state)
73+
![Alt text](src/dp/com/company/state/state.jpg "状态模式类图")
74+
75+
###21.[解释器模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/interpreter)
76+
![Alt text](src/dp/com/company/interpreter/interpreter.jpg "解释器模式类图")
77+
78+
###22.[享元模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/flyweight)
79+
![Alt text](src/dp/com/company/flyweight/flyweight.gif "享元模式类图")
80+
81+
###23.[桥接模式](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/bridge)
82+
![Alt text](src/dp/com/company/bridge/bridge.jpg "桥接模式类图")
83+
84+
###24.[MVC](https://github.com/nivance/DPModel/tree/master/src/dp/com/company/mvc)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apply plugin: 'java'
2+
apply plugin: 'eclipse'
3+
4+
project.group = 'com.company'
5+
project.archivesBaseName = 'dp'
6+
project.version = '1.0.0'
7+
8+
tasks.withType(Compile) { options.encoding = "UTF-8" }
9+
10+
task sourcesJar(type: Jar, dependsOn: classes) {
11+
classifier = 'sources'
12+
from sourceSets.main.allSource
13+
}
14+
15+
artifacts {
16+
archives sourcesJar
17+
}
18+
19+
sourceSets.main.java.srcDirs = ['src/dp']
20+
21+
dependencies {
22+
compile group: 'dom4j', name: 'dom4j', version: '1.6.1'
23+
compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
24+
}
25+
26+
jar {
27+
manifest {
28+
attributes 'Implementation-Title': 'DPModel', 'Implementation-Version': 1.0.0
29+
}
30+
}
31+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#适配器模式(Adapter Pattern)
2+
定义:Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.(将一个类的接口变换成客户端所期待的另一种接口,从而是原本因接口不匹配而无法在一起工作的两个类能够在一起工作。)
3+
4+
5+
适配器模式通用类图如图所示。
6+
![Alt text](adapter.jpg "适配器模式类图")
7+
8+
9+
我们先来看看适配器模式的三个角色:
10+
11+
- Target目标角色:该角色定义把其它类转换为何种接口,也就是我们的期望接口。
12+
- Adaptee源角色:你想把谁转换成目标角色。
13+
- Adapter适配器角色:适配器模式的核心角色,其它两个角色都是已经存在的角色,而适配器角色是需要新建立的,它的职责非常简单,把源角色转换成目标角色,怎么转换?通过继承或类关联的方式。
14+
15+
16+
#适配器模式的应用
17+
##适配器模式的优点
18+
* 适配器模式可以让两个没有任何关系得类在一起运行,只要适配器这个角色能够搞定他就成。
19+
* 增加了类的透明性。我们访问的Target目标角色,但是具体的实现都委托给了源角色,而这些对高层次模块时透明的,也是它不需要关心的。
20+
* 提高了类的复用度。
21+
* 灵活性非常好
22+
23+
##适配器模式的使用场景
24+
适配器应用的场景只要记住一点就足够了:你有动机修改了一个已经投产中的接口时,适配器模式可能是最适合你的模式。
25+
26+
##适配器模式的注意事项
27+
适配器模式最好在详细设计不要考虑它,它不是为了解决还处在开发阶段的问题,而是解决正在服役的项目问题。
23.5 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.company.adapter.section1;
2+
3+
/**
4+
* @author cbf4Life [email protected]
5+
* I'm glad to share my knowledge with you all.
6+
* 这就是我们具体的应用了,比如老板要查所有的20-30的女性信息
7+
*/
8+
public class App {
9+
10+
11+
public static void main(String[] args) {
12+
//没有与外系统连接的时候,是这样写的
13+
//IUserInfo youngGirl = new UserInfo();
14+
15+
//老板一想不对呀,兔子不吃窝边草,还是找人力资源的员工好点
16+
IUserInfo youngGirl = new OuterUserInfo(); //我们只修改了这一句好
17+
//从数据库中查到101个
18+
for(int i=0;i<101;i++){
19+
youngGirl.getMobileNumber();
20+
}
21+
22+
23+
}
24+
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.company.adapter.section1;
2+
3+
import java.util.Map;
4+
5+
/**
6+
* @author cbf4Life [email protected]
7+
* I'm glad to share my knowledge with you all.
8+
* 外系统的人员信息
9+
*/
10+
@SuppressWarnings("all")
11+
public interface IOuterUser {
12+
13+
//基本信息,比如名称,性别,手机号码了等
14+
public Map getUserBaseInfo();
15+
16+
//工作区域信息
17+
public Map getUserOfficeInfo();
18+
19+
//用户的家庭信息
20+
public Map getUserHomeInfo();
21+
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.company.adapter.section1;
2+
3+
/**
4+
* @author cbf4Life [email protected]
5+
* I'm glad to share my knowledge with you all.
6+
* 用户信息对象
7+
*/
8+
public interface IUserInfo {
9+
10+
//获得用户姓名
11+
public String getUserName();
12+
13+
//获得家庭地址
14+
public String getHomeAddress();
15+
16+
//手机号码,这个太重要,手机泛滥呀
17+
public String getMobileNumber();
18+
19+
//办公电话,一般式座机
20+
public String getOfficeTelNumber();
21+
22+
//这个人的职位是啥
23+
public String getJobPosition();
24+
25+
//获得家庭电话,这个有点缺德,我是不喜欢打家庭电话讨论工作
26+
public String getHomeTelNumber();
27+
}

0 commit comments

Comments
 (0)