-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subject:上传目前已经完成的6中设计模式,后面会陆续增加新的,具体计划与安排会陆续在readme中更新。
- Loading branch information
maxy26
committed
Feb 27, 2019
1 parent
41c2155
commit b6bc16e
Showing
100 changed files
with
1,831 additions
and
169 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,29 @@ | ||
# DesignPatterns | ||
|
||
1.观察者模式 - 已上传 | ||
|
||
2.装饰模式- 已上传 | ||
|
||
3.策略模式-已上传 | ||
|
||
4.适配器模式- 已上传 | ||
|
||
5.代理模式- 已上传 | ||
|
||
6.模板模式- 已上传 | ||
|
||
7.工厂模式(抽象)- 整理中 | ||
|
||
8.桥接模式- 整理中 | ||
|
||
9.门面模式- 整理中 | ||
|
||
10.组合模式- 整理中 | ||
|
||
11.状态模式- 整理中 | ||
|
||
12.命令模式- 整理中 | ||
|
||
13.解释器模式- 整理中 | ||
|
||
|
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
11 changes: 11 additions & 0 deletions
11
src/main/com/mxy/design/adapter/classes/adapter/Ps2Connector.java
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 com.mxy.design.adapter.classes.adapter; | ||
|
||
/** | ||
* ps2插口 | ||
*/ | ||
public interface Ps2Connector { | ||
|
||
|
||
void ps2Description(); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/com/mxy/design/adapter/classes/adapter/Ps2UsbAdapter.java
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 @@ | ||
package com.mxy.design.adapter.classes.adapter; | ||
|
||
/** | ||
* 1.类适配器 | ||
* PS2 to Usb 转换口 | ||
*/ | ||
public class Ps2UsbAdapter extends UsbConnectorImpl implements Ps2Connector { | ||
|
||
/** | ||
* 重点:继承你需要适配的类 | ||
*/ | ||
@Override | ||
public void ps2Description() { | ||
System.out.println("正在进行 PS/2适配USB中...."); | ||
usbDescription(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/com/mxy/design/adapter/classes/adapter/PsConnectorImpl.java
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 com.mxy.design.adapter.classes.adapter; | ||
|
||
|
||
public class PsConnectorImpl implements Ps2Connector { | ||
|
||
@Override | ||
public void ps2Description() { | ||
|
||
System.out.println("使用PS/2插口"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/com/mxy/design/adapter/classes/adapter/UsbConnector.java
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 com.mxy.design.adapter.classes.adapter; | ||
|
||
/** | ||
* USB插口 | ||
*/ | ||
public interface UsbConnector { | ||
|
||
|
||
void usbDescription(); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/com/mxy/design/adapter/classes/adapter/UsbConnectorImpl.java
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 com.mxy.design.adapter.classes.adapter; | ||
|
||
/** | ||
* 使用USB插槽 | ||
*/ | ||
public class UsbConnectorImpl implements UsbConnector { | ||
|
||
@Override | ||
public void usbDescription() { | ||
System.out.println("使用USB插口"); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/com/mxy/design/adapter/interfaces/adapter/Adapter.java
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 com.mxy.design.adapter.interfaces.adapter; | ||
|
||
/** | ||
* 接口适配器:重在共享接口功能,并为继承该适配器的类提供各自所需方法 | ||
*/ | ||
public abstract class Adapter implements Port { | ||
|
||
@Override | ||
public void SSH() { | ||
|
||
} | ||
|
||
@Override | ||
public void NET() { | ||
|
||
} | ||
|
||
@Override | ||
public void FTP() { | ||
|
||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/com/mxy/design/adapter/interfaces/adapter/Chat.java
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 @@ | ||
package com.mxy.design.adapter.interfaces.adapter; | ||
/** | ||
* 该类只需要 NET FTP 就够了 所以继承父类并重写 | ||
*/ | ||
public class Chat extends Adapter { | ||
|
||
|
||
@Override | ||
public void NET() { | ||
System.out.println("Chat 开启80端口"); | ||
} | ||
|
||
@Override | ||
public void FTP() { | ||
System.out.println("Chat 开启21端口"); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/com/mxy/design/adapter/interfaces/adapter/Linux.java
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,22 @@ | ||
package com.mxy.design.adapter.interfaces.adapter; | ||
|
||
/** | ||
* 该系统需要全部方法 | ||
*/ | ||
public class Linux implements Port { | ||
|
||
@Override | ||
public void SSH() { | ||
System.out.println("Linux 开启22端口"); | ||
} | ||
|
||
@Override | ||
public void NET() { | ||
System.out.println("Linux 开启80端口"); | ||
} | ||
|
||
@Override | ||
public void FTP() { | ||
System.out.println("Linux 开启21端口"); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/com/mxy/design/adapter/interfaces/adapter/Port.java
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 @@ | ||
package com.mxy.design.adapter.interfaces.adapter; | ||
|
||
/** | ||
* 各种协议端口 | ||
*/ | ||
public interface Port { | ||
|
||
// 远程SSH端口22 | ||
public void SSH(); | ||
|
||
// 网络端口80 | ||
public void NET(); | ||
|
||
// 文件传输FTP端口21 | ||
public void FTP(); | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
src/main/com/mxy/design/adapter/interfaces/adapter/Tomcat.java
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 com.mxy.design.adapter.interfaces.adapter; | ||
|
||
/** | ||
* 该类只需要 NET 就够了 所以继承父类并重写 | ||
*/ | ||
public class Tomcat extends Adapter { | ||
|
||
|
||
@Override | ||
public void NET() { | ||
System.out.println("Tomcat 开启80端口"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/com/mxy/design/adapter/object/adapater/Ps2Connector.java
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 com.mxy.design.adapter.object.adapater; | ||
|
||
/** | ||
* ps2插口 | ||
*/ | ||
public interface Ps2Connector { | ||
|
||
|
||
void ps2Description(); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/com/mxy/design/adapter/object/adapater/Ps2UsbAdapter.java
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,25 @@ | ||
package com.mxy.design.adapter.object.adapater; | ||
|
||
/** | ||
* 1.对象适配器 | ||
* PS2 to Usb 转换口 | ||
*/ | ||
public class Ps2UsbAdapter implements Ps2Connector { | ||
|
||
|
||
/** | ||
* 重点:在适配器里面持有需要适配的对象 | ||
*/ | ||
private UsbConnector usbConnector; | ||
|
||
|
||
public Ps2UsbAdapter(UsbConnector usbConnector) { | ||
this.usbConnector = usbConnector; | ||
} | ||
|
||
@Override | ||
public void ps2Description() { | ||
System.out.println("正在进行 PS/2适配USB中...."); | ||
usbConnector.usbDescription(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/com/mxy/design/adapter/object/adapater/PsConnectorImpl.java
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 com.mxy.design.adapter.object.adapater; | ||
|
||
|
||
public class PsConnectorImpl implements Ps2Connector { | ||
|
||
@Override | ||
public void ps2Description() { | ||
|
||
System.out.println("使用PS/2插口"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/com/mxy/design/adapter/object/adapater/UsbConnector.java
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 com.mxy.design.adapter.object.adapater; | ||
|
||
/** | ||
* USB插口 | ||
*/ | ||
public interface UsbConnector { | ||
|
||
|
||
void usbDescription(); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/com/mxy/design/adapter/object/adapater/UsbConnectorImpl.java
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 com.mxy.design.adapter.object.adapater; | ||
|
||
/** | ||
* 使用USB插槽 | ||
*/ | ||
public class UsbConnectorImpl implements UsbConnector { | ||
|
||
@Override | ||
public void usbDescription() { | ||
System.out.println("使用USB插口"); | ||
} | ||
} |
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 com.mxy.design.decorator; | ||
|
||
public interface Cake { | ||
|
||
/** | ||
* 描述 | ||
*/ | ||
String description(); | ||
|
||
/** | ||
* 花费金额 | ||
*/ | ||
double cost(); | ||
|
||
} |
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 com.mxy.design.decorator; | ||
|
||
public abstract class CakeDecorator implements Cake { | ||
|
||
|
||
protected Cake cake; | ||
|
||
public CakeDecorator(Cake cake) { | ||
this.cake = cake; | ||
} | ||
|
||
} |
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 com.mxy.design.decorator; | ||
|
||
public class CakeImpl implements Cake { | ||
|
||
|
||
@Override | ||
public String description() { | ||
return "蛋糕"; | ||
} | ||
|
||
@Override | ||
public double cost() { | ||
return 10; | ||
} | ||
} |
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,29 @@ | ||
package com.mxy.design.decorator; | ||
|
||
|
||
public class Candle extends CakeDecorator { | ||
|
||
double candleCost = 30; | ||
|
||
public Candle(Cake cake) { | ||
super(cake); | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "蜡烛"; | ||
} | ||
|
||
@Override | ||
public double cost() { | ||
return (candleCost) + (cake.cost()); | ||
} | ||
|
||
/** | ||
* 涨价 | ||
* @param price | ||
*/ | ||
public void risePrice(double price) { | ||
this.candleCost += price; | ||
} | ||
} |
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,25 @@ | ||
package com.mxy.design.decorator; | ||
|
||
public class Fruits extends CakeDecorator { | ||
|
||
double fruitsCost = 20; | ||
|
||
/** | ||
* 构造为了 调用父类方法 | ||
* | ||
* @param cake | ||
*/ | ||
public Fruits(Cake cake) { | ||
super(cake); | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "水果"; | ||
} | ||
|
||
@Override | ||
public double cost() { | ||
return (fruitsCost) + (cake.cost()); | ||
} | ||
} |
Oops, something went wrong.