├── .gitignore
├── LICENSE
├── README.md
├── image
└── qrcode_wechat.jpg
├── patterns
├── behavior
│ ├── chain_of_responsibility
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── io
│ │ │ └── spring2go
│ │ │ └── corespring
│ │ │ ├── ApproveHandler.java
│ │ │ ├── ClientProgram.java
│ │ │ ├── HR.java
│ │ │ ├── Leave.java
│ │ │ ├── ProjectLeader.java
│ │ │ └── TeamLeader.java
│ ├── command
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── io
│ │ │ └── spring2go
│ │ │ └── corespring
│ │ │ └── command
│ │ │ ├── CloseFileCommand.java
│ │ │ ├── Command.java
│ │ │ ├── FileInvoker.java
│ │ │ ├── FileSystemClient.java
│ │ │ ├── FileSystemReceiver.java
│ │ │ ├── FileSystemReceiverUtil.java
│ │ │ ├── OpenFileCommand.java
│ │ │ ├── UnixFileSystemReceiver.java
│ │ │ ├── WindowsFileSystemReceiver.java
│ │ │ ├── WriteFileCommand.java
│ │ │ └── uml.ucls
│ ├── interpreter
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── io
│ │ │ └── spring2go
│ │ │ └── corespring
│ │ │ └── interpreter
│ │ │ ├── App.java
│ │ │ ├── Expression.java
│ │ │ ├── MinusExpression.java
│ │ │ ├── MultiplyExpression.java
│ │ │ ├── NumberExpression.java
│ │ │ ├── PlusExpression.java
│ │ │ └── uml.ucls
│ ├── iterator
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── io
│ │ │ └── spring2go
│ │ │ └── corespring
│ │ │ └── iterator
│ │ │ ├── App.java
│ │ │ ├── Channel.java
│ │ │ ├── ChannelCollection.java
│ │ │ ├── ChannelCollectionImpl.java
│ │ │ ├── ChannelIterator.java
│ │ │ ├── ChannelTypeEnum.java
│ │ │ └── uml.ucls
│ ├── observer
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── io
│ │ │ └── spring2go
│ │ │ └── patterns
│ │ │ └── observer
│ │ │ ├── Follower.java
│ │ │ ├── Observer.java
│ │ │ ├── ObserverPatternMain.java
│ │ │ ├── OfficialAccount.java
│ │ │ ├── Subject.java
│ │ │ └── uml.ucls
│ ├── strategy
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── io
│ │ │ └── spring2go
│ │ │ └── corespring
│ │ │ └── strategy
│ │ │ ├── HeapSortStrategy.java
│ │ │ ├── MergeSortStrategy.java
│ │ │ ├── QuickSortStrategy.java
│ │ │ ├── SortingMainV1.java
│ │ │ ├── SortingMainV2.java
│ │ │ ├── SortingManagerV1.java
│ │ │ ├── SortingManagerV2.java
│ │ │ ├── SortingStrategy.java
│ │ │ ├── SortingType.java
│ │ │ └── uml.ucls
│ └── template
│ │ ├── pom.xml
│ │ └── src
│ │ └── main
│ │ └── java
│ │ └── io
│ │ └── spring2go
│ │ └── patterns
│ │ └── template
│ │ ├── CSVDataParser.java
│ │ ├── DataParser.java
│ │ ├── DatabaseDataParser.java
│ │ └── TemplateMethodMain.java
├── creation
│ ├── abstract-factory
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── io
│ │ │ └── spring2go
│ │ │ └── corespring
│ │ │ └── abstractfactory
│ │ │ ├── AbstractFactoryMain.java
│ │ │ ├── ChineseElectricalFactory.java
│ │ │ ├── ChineseFan.java
│ │ │ ├── ChineseTubeLight.java
│ │ │ ├── IElectricalFactory.java
│ │ │ ├── IFan.java
│ │ │ ├── ITubeLight.java
│ │ │ ├── USElectricalFactory.java
│ │ │ ├── USFan.java
│ │ │ └── USTubeLight.java
│ ├── builder
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── io
│ │ │ └── spring2go
│ │ │ └── corespring
│ │ │ ├── classicbuilder
│ │ │ ├── AndroidPhoneBuilder.java
│ │ │ ├── Battery.java
│ │ │ ├── ClassicBuilderMain.java
│ │ │ ├── IMobilePhoneBuilder.java
│ │ │ ├── Manufacturer.java
│ │ │ ├── MobilePhone.java
│ │ │ ├── OperatingSystem.java
│ │ │ ├── ScreenType.java
│ │ │ ├── Stylus.java
│ │ │ └── WindowsPhoneBuilder.java
│ │ │ ├── javabean
│ │ │ ├── JavaBeanMain.java
│ │ │ └── User.java
│ │ │ ├── modernbuilder
│ │ │ ├── ModernBuilderMain.java
│ │ │ └── User.java
│ │ │ └── telescoping_constructor
│ │ │ └── User.java
│ ├── factory-method
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── io
│ │ │ └── spring2go
│ │ │ └── corespring
│ │ │ └── factorymethod
│ │ │ ├── CeilingFan.java
│ │ │ ├── CeilingFanFactory.java
│ │ │ ├── ExhaustFan.java
│ │ │ ├── ExhaustFanFactory.java
│ │ │ ├── FactoryMethodMain.java
│ │ │ ├── IFan.java
│ │ │ ├── IFanFactory.java
│ │ │ ├── PropellerFan.java
│ │ │ ├── PropellerFanFactory.java
│ │ │ ├── TableFan.java
│ │ │ └── TableFanFactory.java
│ ├── simple-factory
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── io
│ │ │ └── spring2go
│ │ │ └── corespring
│ │ │ ├── nofactory
│ │ │ └── NoFactoryMain.java
│ │ │ └── simplefactory
│ │ │ ├── CeilingFan.java
│ │ │ ├── ExhaustFan.java
│ │ │ ├── FanFactory.java
│ │ │ ├── FanType.java
│ │ │ ├── IFan.java
│ │ │ ├── IFanFactory.java
│ │ │ ├── SimpleFactoryMain.java
│ │ │ └── TableFan.java
│ └── singleton
│ │ ├── filename.ser
│ │ ├── pom.xml
│ │ └── src
│ │ └── main
│ │ └── java
│ │ └── io
│ │ └── spring2go
│ │ └── corespring
│ │ ├── singleton
│ │ ├── v3
│ │ │ └── BillPughSingleton.java
│ │ └── v4
│ │ │ ├── EnumSingleton.java
│ │ │ └── TestEnumSingleton.java
│ │ ├── singleton_deserialization
│ │ ├── DemoSingleton.java
│ │ └── SerializationTest.java
│ │ ├── singleton_reflection
│ │ ├── ReflectionSingleton.java
│ │ └── ReflectionTest.java
│ │ ├── singleton_v1
│ │ └── EagerSingleton.java
│ │ ├── singleton_v1_1
│ │ └── StaticBlockSingleton.java
│ │ ├── singleton_v2
│ │ └── LazySingleton.java
│ │ ├── singleton_v2_1
│ │ └── ThreadSafeSingleton.java
│ │ └── singleton_v2_2
│ │ └── DoubleCheckLockingSingleton.java
├── general
│ └── dependency-inversion
│ │ ├── pom.xml
│ │ └── src
│ │ └── main
│ │ └── java
│ │ └── io
│ │ └── spring2go
│ │ └── corespring
│ │ ├── injection
│ │ ├── AppMonitorConstructorInjection.java
│ │ └── AppMonitorSetterInjection.java
│ │ ├── ioc
│ │ ├── AppMonitorIOC.java
│ │ ├── EmailSender.java
│ │ ├── EventLogWriter.java
│ │ ├── INotifier.java
│ │ └── SMSSender.java
│ │ └── nodip
│ │ └── AppMonitorNoDIP.java
└── structural
│ ├── adapter
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── io
│ │ └── spring2go
│ │ └── corespring
│ │ ├── display
│ │ ├── IHdmi.java
│ │ ├── IVga.java
│ │ ├── LaptopMain.java
│ │ ├── Vga2HdmiAdapter.java
│ │ └── VgaDisplay.java
│ │ └── stack
│ │ ├── ArrayStack.java
│ │ ├── ArrayStackMain.java
│ │ ├── IStack.java
│ │ └── StackException.java
│ ├── bridge
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── io
│ │ └── spring2go
│ │ └── corespring
│ │ └── bridge
│ │ ├── Client.java
│ │ ├── FileDownloadImplementor.java
│ │ ├── FileDownloaderAbstraction.java
│ │ ├── FileDownloaderAbstractionImpl.java
│ │ ├── LinuxFileDownloadImplementor.java
│ │ ├── WindowsFileDownloadImplementor.java
│ │ ├── abstraction_change
│ │ ├── FileDownloaderAbstraction.java
│ │ └── FileDownloaderAbstractionImpl.java
│ │ └── implementation_change
│ │ ├── FileDownloadImplementor.java
│ │ ├── LinuxFileDownloadImplementor.java
│ │ └── WindowsFileDownloadImplementor.java
│ ├── composite
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── io
│ │ └── spring2go
│ │ └── corespring
│ │ ├── composite_complex
│ │ ├── BaseEmployee.java
│ │ ├── CompanyMain.java
│ │ ├── Developer.java
│ │ ├── IEmployee.java
│ │ ├── Manager.java
│ │ ├── Subscription.java
│ │ ├── SubscriptionType.java
│ │ └── Util.java
│ │ └── composite_simple
│ │ ├── CompositePatternMain.java
│ │ ├── Developer.java
│ │ ├── IEmployee.java
│ │ └── Manager.java
│ ├── decorator
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── io
│ │ └── spring2go
│ │ └── corespring
│ │ └── decorator
│ │ ├── ArtificialScentDecorator.java
│ │ ├── BakeryComponent.java
│ │ ├── CakeBase.java
│ │ ├── CherryDecorator.java
│ │ ├── CreamDecorator.java
│ │ ├── Decorator.java
│ │ ├── DecoratorMain.java
│ │ ├── NameCardDecorator.java
│ │ ├── PastryBase.java
│ │ ├── Util.java
│ │ └── uml.ucls
│ ├── facade
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── io
│ │ └── spring2go
│ │ └── corespring
│ │ └── facade
│ │ ├── CostManager.java
│ │ ├── FacadeMain.java
│ │ ├── ICosting.java
│ │ ├── IInventory.java
│ │ ├── ILogistics.java
│ │ ├── IOrderVerify.java
│ │ ├── IPaymentGateway.java
│ │ ├── InventoryManager.java
│ │ ├── LogisticsManager.java
│ │ ├── NoFacadeMain.java
│ │ ├── OnlineShoppingFacade.java
│ │ ├── OrderDetails.java
│ │ ├── OrderVerificationManager.java
│ │ └── PaymentGatewayManager.java
│ └── proxy
│ ├── pom.xml
│ └── src
│ └── main
│ └── java
│ └── io
│ └── spring2go
│ └── corespring
│ ├── Folder.java
│ ├── FolderProxy.java
│ ├── IFolder.java
│ ├── ProxyDesignPatternMain.java
│ ├── User.java
│ └── uml.ucls
└── ppts
├── DIP+IoC+DI.pdf
├── 代理模式.pdf
├── 单例.pdf
├── 命令模式.pdf
├── 工厂方法.pdf
├── 抽象工厂.pdf
├── 构建者.pdf
├── 桥接器.pdf
├── 模板方法模式.pdf
├── 流畅接口.pdf
├── 策略模式.pdf
├── 简单工厂.pdf
├── 组合模式.pdf
├── 职责链模式.pdf
├── 装饰模式.pdf
├── 观察者模式.pdf
├── 解释器模式.pdf
├── 迭代器模式.pdf
├── 适配器.pdf
└── 门面模式.pdf
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | *.iml
19 | .gradle
20 | local.properties
21 | .idea/workspace.xml
22 | .idea/libraries
23 | .DS_Store
24 | build/
25 | captures/
26 | .externalNativeBuild
27 |
28 | ### NetBeans ###
29 | nbproject/private/
30 | build/
31 | nbbuild/
32 | dist/
33 | nbdist/
34 | .nb-gradle/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 spring2go.com
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | core-spring-patterns
2 | ======
3 |
4 | Spring核心原理和模式,波波微课
5 |
6 | ## 大纲
7 |
8 | ### 1. 创建模式
9 |
10 | 名称 | 代码 | ppt | 视频 |
11 | ----|-----|-----|-----|
12 | 简单工厂Simple Factory|[code](patterns/creation/simple-factory)|[ppt](ppts/简单工厂.pdf)|[video](https://v.qq.com/x/page/n0629exrd31.html)|
13 | 工厂方法Factory Method|[code](patterns/creation/factory-method)|[ppt](ppts/工厂方法.pdf)|[video](https://v.qq.com/x/page/a0629kh0xxc.html)|
14 | 抽象工厂Abstract Factory|[code](patterns/creation/abstract-factory)|[ppt](ppts/抽象工厂.pdf)|[video](https://v.qq.com/x/page/p0629psr89t.html)|
15 | 单例Singleton|[code](patterns/creation/singleton)|[ppt](ppts/单例.pdf)|[video](https://v.qq.com/x/page/s0630rqg9wg.html)|
16 | 构造者Builder|[code](patterns/creation/builder)|[ppt](ppts/构建者.pdf)|[video](https://v.qq.com/x/page/z0630bg1qs3.html)|
17 | 流畅接口Fluent Interface|[code](patterns/creation/builder)|[ppt](ppts/流畅接口.pdf)|[video](https://v.qq.com/x/page/v063000n872.html)|
18 |
19 | ### 2. 结构模式
20 |
21 | 名称 | 代码 | ppt | 视频 |
22 | ----|-----|-----|-----|
23 | 适配器Adapter|[code](patterns/structural/adapter)|[ppt](ppts/适配器.pdf)|[video](https://v.qq.com/x/page/w0632njvzkw.html)|
24 | 桥接器Bridge|[code](patterns/structural/bridge)|[ppt](ppts/桥接器.pdf)|[video](https://v.qq.com/x/page/h0632obkktb.html)|
25 | 组合Composite|[code](patterns/structural/composite)|[ppt](ppts/组合模式.pdf)|[video](https://v.qq.com/x/page/t0634x9lbew.html)|
26 | 装饰Decorator|[code](patterns/structural/decorator)|[ppt](ppts/装饰模式.pdf)|[video](http://v.qq.com/x/page/p0636w3d6s2.html)|
27 | 门面Facade|[code](patterns/structural/facade)|[ppt](ppts/门面模式.pdf)|[video](https://v.qq.com/x/page/m06379lgexy.html)|
28 | 代理Proxy|[code](patterns/structural/proxy)|[ppt](ppts/代理模式.pdf)|[video](https://v.qq.com/x/page/k0637354wuw.html)|
29 |
30 |
31 | ### 3. 行为模式
32 |
33 | 名称 | 代码 | ppt | 视频 |
34 | ----|-----|-----|-----|
35 | 职责链Chain of Responsibility|[code](patterns/behavior/chain_of_responsibility)|[ppt](ppts/职责链模式.pdf)|[video](http://v.qq.com/x/page/r0640omm9hs.html)|
36 | 命令Command|[code](patterns/behavior/command)|[ppt](ppts/命令模式.pdf)|[video](https://v.qq.com/x/page/j0641ba2m4j.html)|
37 | 解释器Interpreter|[code](patterns/behavior/interpreter)|[ppt](ppts/解释器模式.pdf)|[video](http://v.qq.com/x/page/t0642g9ioam.html)|
38 | 迭代器Iterator|[code](patterns/behavior/iterator)|[ppt](ppts/迭代器模式.pdf)|[video](https://v.qq.com/x/page/a0643uhcvgn.html)|
39 | 策略Strategy|[code](patterns/behavior/strategy)|[ppt](ppts/策略模式.pdf)|[video](http://v.qq.com/x/page/n0645457b19.html)|
40 | 观察者Observer|[code](patterns/behavior/observer)|[ppt](ppts/观察者模式.pdf)|[video](http://v.qq.com/x/page/j0653cekdal.html)|
41 | 模板方法Template Method|[code](patterns/behavior/template)|[ppt](ppts/模板方法模式.pdf)|[video](https://v.qq.com/x/page/p0654hjkpy3.html)|
42 |
43 | ### 4. 核心模式
44 |
45 | 名称 | 代码 | ppt | 视频 |
46 | ----|-----|-----|-----|
47 | 依赖倒置原则,控制反转,依赖注入|[code](patterns/general/dependency-inversion)|[ppt](ppts/DIP+IoC+DI.pdf)|[video](https://v.qq.com/x/page/k0629qsrpz5.html)|
48 |
49 | ## 波波微课公众号
50 |
51 | 
52 |
53 | ## 官网
54 |
55 | [jskillcloud.com](http://www.jskillcloud.com)
56 |
--------------------------------------------------------------------------------
/image/qrcode_wechat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/image/qrcode_wechat.jpg
--------------------------------------------------------------------------------
/patterns/behavior/chain_of_responsibility/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | ChainOfResponsibility
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/behavior/chain_of_responsibility/src/main/java/io/spring2go/corespring/ApproveHandler.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | // Handler
4 | public interface ApproveHandler {
5 |
6 | public void setNextHandler(ApproveHandler nextHandler);
7 |
8 | public void approve(Leave leave);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/behavior/chain_of_responsibility/src/main/java/io/spring2go/corespring/ClientProgram.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | // Client
4 | public class ClientProgram {
5 |
6 | public static void main(String[] args) {
7 | TeamLeader tl = new TeamLeader();
8 | ProjectLeader pl = new ProjectLeader();
9 | HR hr = new HR();
10 |
11 | tl.setNextHandler(pl);
12 | pl.setNextHandler(hr);
13 |
14 |
15 | tl.approve(new Leave(1, 5));
16 | tl.approve(new Leave(2, 15));
17 | tl.approve(new Leave(3, 25));
18 | tl.approve(new Leave(4, 35));
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/patterns/behavior/chain_of_responsibility/src/main/java/io/spring2go/corespring/HR.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | //ConcreteHandler
4 | public class HR implements ApproveHandler {
5 |
6 | private ApproveHandler nextHandler;
7 |
8 | public final static int MAX_LEAVES_CAN_APPROVE = 30;
9 |
10 | public void setNextHandler(ApproveHandler nextHandler) {
11 | this.nextHandler = nextHandler;
12 | }
13 |
14 | public void approve(Leave leave) {
15 | if (leave.getNumberOfDays() < MAX_LEAVES_CAN_APPROVE) {
16 | String output = String.format(
17 | "LeaveId: %d, Days: %d, Approver: %s",
18 | leave.getLeaveId(),
19 | leave.getNumberOfDays(),
20 | "HR");
21 | System.out.println(output);
22 | } else {
23 | if (nextHandler != null) {
24 | nextHandler.approve(leave);
25 | } else {
26 | System.out.println("Leave application suspended, Please contact HR");
27 | }
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/patterns/behavior/chain_of_responsibility/src/main/java/io/spring2go/corespring/Leave.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | // 请求对象
4 | public class Leave {
5 | private int leaveId;
6 | private int numberOfDays;
7 |
8 | public Leave(int leaveId, int numberOfDays) {
9 | this.leaveId = leaveId;
10 | this.numberOfDays = numberOfDays;
11 | }
12 |
13 | // region getter/setter
14 | public int getLeaveId() {
15 | return leaveId;
16 | }
17 |
18 | public void setLeaveId(int leaveId) {
19 | this.leaveId = leaveId;
20 | }
21 |
22 | public int getNumberOfDays() {
23 | return numberOfDays;
24 | }
25 |
26 | public void setNumberOfDays(int numberOfDays) {
27 | this.numberOfDays = numberOfDays;
28 | }
29 | // endregion
30 | }
31 |
--------------------------------------------------------------------------------
/patterns/behavior/chain_of_responsibility/src/main/java/io/spring2go/corespring/ProjectLeader.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | //ConcreteHandler
4 | public class ProjectLeader implements ApproveHandler {
5 |
6 | private ApproveHandler nextHandler;
7 |
8 | public final static int MAX_LEAVES_CAN_APPROVE = 20;
9 |
10 | public void setNextHandler(ApproveHandler nextHandler) {
11 | this.nextHandler = nextHandler;
12 | }
13 |
14 | public void approve(Leave leave) {
15 | if (leave.getNumberOfDays() < MAX_LEAVES_CAN_APPROVE) {
16 | String output = String.format(
17 | "LeaveId: %d, Days: %d, Approver: %s",
18 | leave.getLeaveId(),
19 | leave.getNumberOfDays(),
20 | "ProjectLeader");
21 | System.out.println(output);
22 | } else {
23 | if (nextHandler != null) {
24 | nextHandler.approve(leave);
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/patterns/behavior/chain_of_responsibility/src/main/java/io/spring2go/corespring/TeamLeader.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | // ConcreteHandler
4 | public class TeamLeader implements ApproveHandler {
5 |
6 | private ApproveHandler nextHandler;
7 |
8 | public final static int MAX_LEAVES_CAN_APPROVE = 10;
9 |
10 | public void setNextHandler(ApproveHandler nextHandler) {
11 | this.nextHandler = nextHandler;
12 | }
13 |
14 | public void approve(Leave leave) {
15 | if (leave.getNumberOfDays() < MAX_LEAVES_CAN_APPROVE) {
16 | String output = String.format(
17 | "LeaveId: %d, Days: %d, Approver: %s",
18 | leave.getLeaveId(),
19 | leave.getNumberOfDays(),
20 | "TeamLeader");
21 | System.out.println(output);
22 | } else {
23 | if (nextHandler != null) {
24 | nextHandler.approve(leave);
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/patterns/behavior/command/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Command
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/CloseFileCommand.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.command;
2 |
3 | // Concrete Command
4 | public class CloseFileCommand implements Command {
5 |
6 | private FileSystemReceiver fileSystem;
7 |
8 | public CloseFileCommand(FileSystemReceiver fs) {
9 | this.fileSystem = fs;
10 | }
11 |
12 | @Override
13 | public void execute() {
14 | this.fileSystem.closeFile();
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/Command.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.command;
2 |
3 | // Command interface
4 | public interface Command {
5 |
6 | void execute();
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/FileInvoker.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.command;
2 |
3 | // Invoker
4 | public class FileInvoker {
5 |
6 | private Command command;
7 |
8 | public FileInvoker(Command c) {
9 | this.command = c;
10 | }
11 |
12 | public void execute() {
13 | this.command.execute();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/FileSystemClient.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.command;
2 |
3 | // Client
4 | public class FileSystemClient {
5 |
6 | public static void main(String[] args) {
7 | // creating the receiver object
8 | FileSystemReceiver fs = FileSystemReceiverUtil.getUnderlyingFileSystem();
9 |
10 | // creating command and associating with receiver
11 | OpenFileCommand openFileCommand = new OpenFileCommand(fs);
12 |
13 | // creating invoker and associating with Command
14 | FileInvoker file = new FileInvoker(openFileCommand);
15 |
16 | // perform action on invoker object
17 | file.execute();
18 |
19 | WriteFileCommand writeFileCommand = new WriteFileCommand(fs);
20 | file = new FileInvoker(writeFileCommand);
21 | file.execute();
22 |
23 | CloseFileCommand closeFileCommand = new CloseFileCommand(fs);
24 | file = new FileInvoker(closeFileCommand);
25 | file.execute();
26 |
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/FileSystemReceiver.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.command;
2 |
3 | // Receiver Interface
4 | public interface FileSystemReceiver {
5 | void openFile();
6 | void writeFile();
7 | void closeFile();
8 | }
9 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/FileSystemReceiverUtil.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.command;
2 |
3 | public class FileSystemReceiverUtil {
4 |
5 | public static FileSystemReceiver getUnderlyingFileSystem() {
6 | String osName = System.getProperty("os.name");
7 | System.out.println("Underlying OS is : " + osName);
8 | if (osName.contains("Windows")) {
9 | return new WindowsFileSystemReceiver();
10 | } else {
11 | return new UnixFileSystemReceiver();
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/OpenFileCommand.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.command;
2 |
3 | // Concrete Command
4 | public class OpenFileCommand implements Command {
5 |
6 | private FileSystemReceiver fileSystem;
7 |
8 | public OpenFileCommand(FileSystemReceiver fs) {
9 | this.fileSystem = fs;
10 | }
11 |
12 | @Override
13 | public void execute() {
14 | // open command is forwarding request to openFile method
15 | this.fileSystem.openFile();
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/UnixFileSystemReceiver.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.command;
2 |
3 | // Receiver
4 | public class UnixFileSystemReceiver implements FileSystemReceiver {
5 |
6 | @Override
7 | public void openFile() {
8 | System.out.println("Opening file in unix OS");
9 | }
10 |
11 | @Override
12 | public void writeFile() {
13 | System.out.println("Writing file in unix OS");
14 | }
15 |
16 | @Override
17 | public void closeFile() {
18 | System.out.println("Closing file in unix OS");
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/WindowsFileSystemReceiver.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.command;
2 |
3 | // Receiver
4 | public class WindowsFileSystemReceiver implements FileSystemReceiver {
5 |
6 | @Override
7 | public void openFile() {
8 | System.out.println("Opening file in Windows OS");
9 | }
10 |
11 | @Override
12 | public void writeFile() {
13 | System.out.println("Writing file in Windows OS");
14 | }
15 |
16 | @Override
17 | public void closeFile() {
18 | System.out.println("Closing file in Windows OS");
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/WriteFileCommand.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.command;
2 |
3 | // Concrete Command
4 | public class WriteFileCommand implements Command {
5 |
6 | private FileSystemReceiver fileSystem;
7 |
8 | public WriteFileCommand(FileSystemReceiver fs) {
9 | this.fileSystem = fs;
10 | }
11 |
12 | @Override
13 | public void execute() {
14 | this.fileSystem.writeFile();
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/patterns/behavior/command/src/main/java/io/spring2go/corespring/command/uml.ucls:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
36 |
37 |
39 |
40 |
41 |
42 |
43 |
46 |
47 |
49 |
50 |
51 |
52 |
53 |
56 |
57 |
59 |
60 |
61 |
62 |
63 |
66 |
67 |
69 |
70 |
71 |
72 |
73 |
76 |
77 |
79 |
80 |
81 |
82 |
83 |
85 |
86 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
146 |
147 |
148 |
149 |
150 |
--------------------------------------------------------------------------------
/patterns/behavior/interpreter/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Interpreter
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/patterns/behavior/interpreter/src/main/java/io/spring2go/corespring/interpreter/App.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.interpreter;
2 |
3 | import java.util.Stack;
4 |
5 | // Interpreter
6 | public class App {
7 |
8 | /**
9 | * Expression can be evaluated using prefix, infix or postfix notations
10 | * This sample uses postfix, where operator comes after the operands.
11 | */
12 | public static void main(String[] args) {
13 | String tokenString = "4 3 2 - 1 + *"; // (3 - 2 + 1) * 4
14 | Stack stack = new Stack<>();
15 |
16 | String[] tokenList = tokenString.split(" ");
17 | for(String s : tokenList) {
18 | if (isOperator(s)) {
19 | Expression rightExpression = stack.pop();
20 | Expression leftExpression = stack.pop();
21 | Expression operator =
22 | getOperatorInstance(s, leftExpression, rightExpression);
23 | int result = operator.interpret();
24 | NumberExpression resultExpression = new NumberExpression(result);
25 | stack.push(resultExpression);
26 | } else {
27 | Expression i = new NumberExpression(s);
28 | stack.push(i);
29 | }
30 | }
31 |
32 | System.out.println("result: " + stack.pop().interpret());
33 | }
34 |
35 | public static boolean isOperator(String s) {
36 | return s.equals("+") || s.equals("-") || s.equals("*");
37 | }
38 |
39 | // Get expression for string
40 | public static Expression getOperatorInstance(
41 | String s, Expression left, Expression right) {
42 | switch (s) {
43 | case "+":
44 | return new PlusExpression(left, right);
45 | case "-":
46 | return new MinusExpression(left, right);
47 | case "*":
48 | return new MultiplyExpression(left, right);
49 | default:
50 | return new MultiplyExpression(left, right);
51 | }
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/patterns/behavior/interpreter/src/main/java/io/spring2go/corespring/interpreter/Expression.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.interpreter;
2 |
3 | // Expression
4 | public abstract class Expression {
5 |
6 | public abstract int interpret();
7 |
8 | @Override
9 | public abstract String toString();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/patterns/behavior/interpreter/src/main/java/io/spring2go/corespring/interpreter/MinusExpression.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.interpreter;
2 |
3 | // MinusExpression
4 | public class MinusExpression extends Expression {
5 |
6 | private Expression leftExpression;
7 | private Expression rightExpression;
8 |
9 | public MinusExpression(
10 | Expression leftExpression,
11 | Expression rightExpression) {
12 | this.leftExpression = leftExpression;
13 | this.rightExpression = rightExpression;
14 | }
15 |
16 | @Override
17 | public int interpret() {
18 | return leftExpression.interpret() - rightExpression.interpret();
19 | }
20 |
21 | @Override
22 | public String toString() {
23 | return "-";
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/patterns/behavior/interpreter/src/main/java/io/spring2go/corespring/interpreter/MultiplyExpression.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.interpreter;
2 |
3 | // MultiplyExpression
4 | public class MultiplyExpression extends Expression {
5 |
6 | private Expression leftExpression;
7 | private Expression rightExpression;
8 |
9 | public MultiplyExpression(
10 | Expression leftExpression,
11 | Expression rightExpression) {
12 | this.leftExpression = leftExpression;
13 | this.rightExpression = rightExpression;
14 | }
15 |
16 | @Override
17 | public int interpret() {
18 | return leftExpression.interpret() * rightExpression.interpret();
19 | }
20 |
21 | @Override
22 | public String toString() {
23 | return "*";
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/patterns/behavior/interpreter/src/main/java/io/spring2go/corespring/interpreter/NumberExpression.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.interpreter;
2 |
3 | // NumberExpression
4 | public class NumberExpression extends Expression {
5 |
6 | private int number;
7 |
8 | public NumberExpression(int number) {
9 | this.number = number;
10 | }
11 |
12 | public NumberExpression(String s) {
13 | this.number = Integer.parseInt(s);
14 | }
15 |
16 | @Override
17 | public int interpret() {
18 | return number;
19 | }
20 |
21 | @Override
22 | public String toString() {
23 | return "number";
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/patterns/behavior/interpreter/src/main/java/io/spring2go/corespring/interpreter/PlusExpression.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.interpreter;
2 |
3 | // PlusExpression
4 | public class PlusExpression extends Expression {
5 |
6 | private Expression leftExpression;
7 | private Expression rightExpression;
8 |
9 | public PlusExpression(
10 | Expression leftExpression,
11 | Expression rightExpression) {
12 | this.leftExpression = leftExpression;
13 | this.rightExpression = rightExpression;
14 | }
15 |
16 | @Override
17 | public int interpret() {
18 | return leftExpression.interpret() + rightExpression.interpret();
19 | }
20 |
21 | @Override
22 | public String toString() {
23 | return "+";
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/patterns/behavior/interpreter/src/main/java/io/spring2go/corespring/interpreter/uml.ucls:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
37 |
38 |
40 |
41 |
42 |
43 |
44 |
47 |
48 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/patterns/behavior/iterator/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Iterator
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/behavior/iterator/src/main/java/io/spring2go/corespring/iterator/App.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.iterator;
2 |
3 | // Client App
4 | public class App {
5 |
6 | public static void main(String[] args) {
7 | ChannelCollection channels = populateChannels();
8 | ChannelIterator baseIterator = channels.iterator(ChannelTypeEnum.ALL);
9 | while (baseIterator.hasNext()) {
10 | Channel c = baseIterator.next();
11 | System.out.println(c.toString());
12 | }
13 | System.out.println("******");
14 | // Channel Type Iterator
15 | ChannelIterator englishIterator = channels.iterator(ChannelTypeEnum.ENGLISH);
16 | while (englishIterator.hasNext()) {
17 | Channel c = englishIterator.next();
18 | System.out.println(c.toString());
19 | }
20 | }
21 |
22 | private static ChannelCollection populateChannels() {
23 | ChannelCollection channels = new ChannelCollectionImpl();
24 | channels.addChannel(new Channel(98.5, ChannelTypeEnum.ENGLISH));
25 | channels.addChannel(new Channel(99.5, ChannelTypeEnum.CHINESE));
26 | channels.addChannel(new Channel(100.5, ChannelTypeEnum.FRENCH));
27 | channels.addChannel(new Channel(101.5, ChannelTypeEnum.ENGLISH));
28 | channels.addChannel(new Channel(102.5, ChannelTypeEnum.CHINESE));
29 | channels.addChannel(new Channel(103.5, ChannelTypeEnum.FRENCH));
30 | channels.addChannel(new Channel(104.5, ChannelTypeEnum.ENGLISH));
31 | channels.addChannel(new Channel(105.5, ChannelTypeEnum.CHINESE));
32 | channels.addChannel(new Channel(106.5, ChannelTypeEnum.FRENCH));
33 | return channels;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/patterns/behavior/iterator/src/main/java/io/spring2go/corespring/iterator/Channel.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.iterator;
2 |
3 | public class Channel {
4 | private double frequency;
5 | private ChannelTypeEnum type;
6 |
7 | public Channel(double freq, ChannelTypeEnum type) {
8 | this.frequency = freq;
9 | this.type = type;
10 | }
11 |
12 | public double getFrequency() {
13 | return frequency;
14 | }
15 |
16 | public ChannelTypeEnum getType() {
17 | return type;
18 | }
19 |
20 | @Override
21 | public String toString() {
22 | return "Frequency = " + this.frequency + ", Type = " + this.type;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/patterns/behavior/iterator/src/main/java/io/spring2go/corespring/iterator/ChannelCollection.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.iterator;
2 |
3 | // Aggregate
4 | public interface ChannelCollection {
5 |
6 | public void addChannel(Channel c);
7 |
8 | public void removeChannel(Channel c);
9 |
10 | public ChannelIterator iterator(ChannelTypeEnum type);
11 | }
12 |
--------------------------------------------------------------------------------
/patterns/behavior/iterator/src/main/java/io/spring2go/corespring/iterator/ChannelCollectionImpl.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.iterator;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | // ConcreteAggregate
7 | public class ChannelCollectionImpl implements ChannelCollection {
8 |
9 | private List channelList;
10 |
11 | public ChannelCollectionImpl() {
12 | channelList = new ArrayList<>();
13 | }
14 |
15 | @Override
16 | public void addChannel(Channel c) {
17 | this.channelList.add(c);
18 | }
19 |
20 | @Override
21 | public void removeChannel(Channel c) {
22 | this.channelList.remove(c);
23 | }
24 |
25 | @Override
26 | public ChannelIterator iterator(ChannelTypeEnum type) {
27 | return new ChannelIteratorImpl(type, this.channelList);
28 | }
29 |
30 | // ConcreteIterator
31 | private class ChannelIteratorImpl implements ChannelIterator {
32 | private ChannelTypeEnum type;
33 | private List channels;
34 | private int position;
35 |
36 | public ChannelIteratorImpl(ChannelTypeEnum type,
37 | List channelList) {
38 | this.type = type;
39 | this.channels = channelList;
40 | }
41 |
42 | @Override
43 | public boolean hasNext() {
44 | while (position < channels.size()) {
45 | Channel c = channels.get(position);
46 | if (c.getType().equals(type) ||
47 | type.equals(ChannelTypeEnum.ALL)) {
48 | return true;
49 | } else {
50 | position++;
51 | }
52 | }
53 | return false;
54 | }
55 |
56 | @Override
57 | public Channel next() {
58 | Channel c = channels.get(position);
59 | position++;
60 | return c;
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/patterns/behavior/iterator/src/main/java/io/spring2go/corespring/iterator/ChannelIterator.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.iterator;
2 |
3 | // Iterator
4 | public interface ChannelIterator {
5 |
6 | public boolean hasNext();
7 |
8 | public Channel next();
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/behavior/iterator/src/main/java/io/spring2go/corespring/iterator/ChannelTypeEnum.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.iterator;
2 |
3 | public enum ChannelTypeEnum {
4 | ENGLISH, CHINESE, FRENCH, ALL;
5 | }
6 |
--------------------------------------------------------------------------------
/patterns/behavior/iterator/src/main/java/io/spring2go/corespring/iterator/uml.ucls:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
36 |
37 |
39 |
40 |
41 |
42 |
43 |
46 |
47 |
49 |
50 |
51 |
52 |
53 |
56 |
57 |
59 |
60 |
61 |
62 |
63 |
65 |
66 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/patterns/behavior/observer/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.patterns
5 | Observer
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/behavior/observer/src/main/java/io/spring2go/patterns/observer/Follower.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.patterns.observer;
2 |
3 | public class Follower implements Observer {
4 |
5 | private String followerName;
6 |
7 | public Follower(String followerName) {
8 | this.followerName = followerName;
9 | }
10 |
11 | @Override
12 | public void update(String oaName, String article) {
13 | System.out.println(followerName + " has received "
14 | + oaName + "'s article :: " + article );
15 | }
16 |
17 | @Override
18 | public String toString() {
19 | return followerName;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/patterns/behavior/observer/src/main/java/io/spring2go/patterns/observer/Observer.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.patterns.observer;
2 |
3 | // The Observers are notified when the Subject changes
4 | public interface Observer {
5 |
6 | public void update(String name, String s);
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/patterns/behavior/observer/src/main/java/io/spring2go/patterns/observer/ObserverPatternMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.patterns.observer;
2 |
3 | public class ObserverPatternMain {
4 |
5 | public static void main(String[] args) {
6 | OfficialAccount bobo = new OfficialAccount("bobo");
7 | OfficialAccount infoq = new OfficialAccount("infoq");
8 |
9 | Follower mark = new Follower("Mark");
10 | Follower eric = new Follower("Eric");
11 | Follower jack = new Follower("Jack");
12 | Follower frank = new Follower("Frank");
13 | Follower daniel = new Follower("Daniel");
14 | Follower alice = new Follower("Alice");
15 |
16 | bobo.register(mark);
17 | bobo.register(eric);
18 | bobo.register(jack);
19 |
20 | infoq.register(frank);
21 | infoq.register(daniel);
22 | infoq.register(alice);
23 |
24 | bobo.pushArticle("observer design pattern video course");
25 | infoq.pushArticle("spring 5.0 is out");
26 |
27 | bobo.unregister(eric);
28 |
29 | bobo.pushArticle("core java course is released");
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/patterns/behavior/observer/src/main/java/io/spring2go/patterns/observer/OfficialAccount.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.patterns.observer;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class OfficialAccount implements Subject {
7 |
8 | private String oaName;
9 | private List followers;
10 |
11 | public OfficialAccount(String oaName) {
12 | this.oaName = oaName;
13 | followers = new ArrayList();
14 | }
15 |
16 | @Override
17 | public void register(Observer o) {
18 | followers.add(o);
19 | System.out.println(o + " has started following " + oaName);
20 | }
21 |
22 | @Override
23 | public void unregister(Observer o) {
24 | followers.remove(o);
25 | System.out.println(o + " has stopped following " + oaName);
26 | }
27 |
28 | @Override
29 | public void notifyAllObservers(String article) {
30 | for(Observer follower : followers) {
31 | follower.update(oaName, article);
32 | }
33 | System.out.println();
34 | }
35 |
36 | public void pushArticle(String article) {
37 | System.out.println("\n" + oaName + " has pushed :: " + article);
38 | notifyAllObservers(article);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/patterns/behavior/observer/src/main/java/io/spring2go/patterns/observer/Subject.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.patterns.observer;
2 |
3 | // interface for adding, deleting
4 | // and updating all observers
5 | public interface Subject {
6 | public void register(Observer o);
7 | public void unregister(Observer o);
8 | public void notifyAllObservers(String s);
9 | }
10 |
--------------------------------------------------------------------------------
/patterns/behavior/observer/src/main/java/io/spring2go/patterns/observer/uml.ucls:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
34 |
35 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Strategy
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/src/main/java/io/spring2go/corespring/strategy/HeapSortStrategy.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.strategy;
2 |
3 | import java.util.List;
4 |
5 | public class HeapSortStrategy implements SortingStrategy {
6 |
7 | @Override
8 | public void sort(List list) {
9 | System.out.println("Sorting using heap sort");
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/src/main/java/io/spring2go/corespring/strategy/MergeSortStrategy.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.strategy;
2 |
3 | import java.util.List;
4 |
5 | // ConcreteStrategy
6 | public class MergeSortStrategy implements SortingStrategy {
7 |
8 | @Override
9 | public void sort(List list) {
10 | System.out.println("Sorting List using merge sort");
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/src/main/java/io/spring2go/corespring/strategy/QuickSortStrategy.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.strategy;
2 |
3 | import java.util.List;
4 |
5 | // ConcreteStrategy
6 | public class QuickSortStrategy implements SortingStrategy {
7 |
8 | @Override
9 | public void sort(List list) {
10 | System.out.println("Sorting List using quick sort");
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/src/main/java/io/spring2go/corespring/strategy/SortingMainV1.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.strategy;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | public class SortingMainV1 {
7 | public static void main(String[] args) {
8 | List list = Arrays.asList(new Integer[] { 44, 5, 3, 5, 5, 64, 3 });
9 |
10 | SortingManagerV1 sm = new SortingManagerV1(list);
11 |
12 | // Sorting using merge sort
13 | sm.sortListBasedOnType(SortingType.MERGE_SORT);
14 |
15 | System.out.println();
16 |
17 | // Sorting using quick sort
18 | sm.sortListBasedOnType(SortingType.QUICK_SORT);
19 |
20 | System.out.println();
21 |
22 | // Sorting using heap sort
23 | sm.sortListBasedOnType(SortingType.HEAP_SORT);
24 |
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/src/main/java/io/spring2go/corespring/strategy/SortingMainV2.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.strategy;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | public class SortingMainV2 {
7 |
8 | public static void main(String[] args) {
9 | List list = Arrays.asList(new Integer[] { 44, 5, 3, 5, 5, 64, 3 });
10 | MergeSortStrategy mergeSortStrategy = new MergeSortStrategy();
11 | SortingManagerV2 sm = new SortingManagerV2(list, mergeSortStrategy);
12 | sm.sortList();
13 |
14 | System.out.println();
15 |
16 | QuickSortStrategy quickSort = new QuickSortStrategy();
17 | sm.setSortingStrategy(quickSort);
18 | sm.sortList();
19 |
20 | System.out.println();
21 |
22 | HeapSortStrategy heapSort = new HeapSortStrategy();
23 | sm.setSortingStrategy(heapSort);
24 | sm.sortList();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/src/main/java/io/spring2go/corespring/strategy/SortingManagerV1.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.strategy;
2 |
3 | import java.util.List;
4 |
5 | public class SortingManagerV1 {
6 | List list;
7 |
8 | public SortingManagerV1(List list) {
9 | this.list = list;
10 | }
11 |
12 | public void sortListBasedOnType(SortingType sortingType) {
13 | System.out.println("===================================");
14 | System.out.println("Sorting List based on Type");
15 | System.out.println("===================================");
16 |
17 | if (SortingType.MERGE_SORT == sortingType) {
18 | sortListUsingMergeSort();
19 | } else if (SortingType.QUICK_SORT == sortingType) {
20 | sortListUsingQuickSort();
21 | } else if (SortingType.HEAP_SORT == sortingType) {
22 | sortListUsingHeapSort();
23 | }
24 | }
25 |
26 | private void sortListUsingMergeSort() {
27 | System.out.println("Sorting List using merge sort");
28 | }
29 |
30 | private void sortListUsingQuickSort() {
31 | System.out.println("Sorting List using quick sort");
32 | }
33 |
34 | private void sortListUsingHeapSort() {
35 | System.out.println("Sorting List using heap sort");
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/src/main/java/io/spring2go/corespring/strategy/SortingManagerV2.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.strategy;
2 |
3 | import java.util.List;
4 |
5 | public class SortingManagerV2 {
6 | SortingStrategy sortingStrategy;
7 | List list;
8 |
9 | public SortingManagerV2(List list, SortingStrategy sortingStrategy) {
10 | super();
11 | this.list = list;
12 | this.sortingStrategy = sortingStrategy;
13 | }
14 |
15 | public void sortList() {
16 | System.out.println("===================================");
17 | System.out.println("Sorting List based on Type");
18 | System.out.println("===================================");
19 |
20 | sortingStrategy.sort(list);
21 | }
22 |
23 | public SortingStrategy getSortingStrategy() {
24 | return sortingStrategy;
25 | }
26 |
27 | public void setSortingStrategy(SortingStrategy sortingStrategy) {
28 | this.sortingStrategy = sortingStrategy;
29 | }
30 |
31 | public List getList() {
32 | return list;
33 | }
34 |
35 | public void setList(List list) {
36 | this.list = list;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/src/main/java/io/spring2go/corespring/strategy/SortingStrategy.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.strategy;
2 |
3 | import java.util.List;
4 |
5 | // Strategy
6 | public interface SortingStrategy {
7 | void sort(List list);
8 | }
9 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/src/main/java/io/spring2go/corespring/strategy/SortingType.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.strategy;
2 |
3 | public enum SortingType {
4 | MERGE_SORT, QUICK_SORT, HEAP_SORT;
5 | }
6 |
--------------------------------------------------------------------------------
/patterns/behavior/strategy/src/main/java/io/spring2go/corespring/strategy/uml.ucls:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
37 |
38 |
40 |
41 |
42 |
43 |
44 |
47 |
48 |
50 |
51 |
52 |
53 |
54 |
57 |
58 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/patterns/behavior/template/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.patterns.template
5 | Template
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/behavior/template/src/main/java/io/spring2go/patterns/template/CSVDataParser.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.patterns.template;
2 |
3 | public class CSVDataParser extends DataParser {
4 |
5 | @Override
6 | void readData() {
7 | System.out.println("Reading data from csv file");
8 | }
9 |
10 | @Override
11 | void processData() {
12 | System.out.println("Looping through loaded csv file");
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/patterns/behavior/template/src/main/java/io/spring2go/patterns/template/DataParser.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.patterns.template;
2 |
3 | abstract class DataParser {
4 |
5 | // generic data processing flow
6 | public final void process() {
7 | readData();
8 | processData();
9 | writeData();
10 | }
11 |
12 | // implemented by subclass
13 | abstract void readData();
14 | abstract void processData();
15 |
16 | // same for all subclass
17 | public void writeData() {
18 | System.out.println("Ouput generated, writing to CSV");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/patterns/behavior/template/src/main/java/io/spring2go/patterns/template/DatabaseDataParser.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.patterns.template;
2 |
3 | public class DatabaseDataParser extends DataParser {
4 |
5 | @Override
6 | void readData() {
7 | System.out.println("Reading data from database");
8 | }
9 |
10 | @Override
11 | void processData() {
12 | System.out.println("Looping through records in DB");
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/patterns/behavior/template/src/main/java/io/spring2go/patterns/template/TemplateMethodMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.patterns.template;
2 |
3 | public class TemplateMethodMain {
4 |
5 | public static void main(String[] args) {
6 | CSVDataParser csvDataParser = new CSVDataParser();
7 | csvDataParser.process();
8 | System.out.println("**********************");
9 | DatabaseDataParser databaseDataParser = new DatabaseDataParser();
10 | databaseDataParser.process();
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | AbstractFactory
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/src/main/java/io/spring2go/corespring/abstractfactory/AbstractFactoryMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.abstractfactory;
2 |
3 | public class AbstractFactoryMain {
4 |
5 | public static void main(String[] args) {
6 |
7 | // 国产
8 | IElectricalFactory electricalFactory = new ChineseElectricalFactory();
9 |
10 | IFan fan = electricalFactory.createFan();
11 |
12 | fan.swithOn();
13 |
14 | // 美产
15 | electricalFactory = new USElectricalFactory();
16 |
17 | ITubeLight tubeLight = electricalFactory.createTubeLight();
18 | tubeLight.swithOn();
19 | tubeLight.tuneLight();
20 |
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/src/main/java/io/spring2go/corespring/abstractfactory/ChineseElectricalFactory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.abstractfactory;
2 |
3 | public class ChineseElectricalFactory implements IElectricalFactory {
4 |
5 | public IFan createFan() {
6 | return new ChineseFan();
7 | }
8 |
9 | public ITubeLight createTubeLight() {
10 | return new ChineseTubeLight();
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/src/main/java/io/spring2go/corespring/abstractfactory/ChineseFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.abstractfactory;
2 |
3 | public class ChineseFan implements IFan {
4 |
5 | public void swithOn() {
6 | System.out.println("The ChineseFan is swithed on ...");
7 | }
8 |
9 | public void switchOff() {
10 | System.out.println("The ChineseFan is swithed off ...");
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/src/main/java/io/spring2go/corespring/abstractfactory/ChineseTubeLight.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.abstractfactory;
2 |
3 | public class ChineseTubeLight implements ITubeLight {
4 | public void swithOn() {
5 | System.out.println("The ChineseTubeLight is swithed on ...");
6 | }
7 |
8 | public void switchOff() {
9 | System.out.println("The ChineseTubeLight is swithed off ...");
10 | }
11 |
12 | public void tuneLight() {
13 | System.out.println("The ChineseTubeLight is tuned ...");
14 |
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/src/main/java/io/spring2go/corespring/abstractfactory/IElectricalFactory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.abstractfactory;
2 |
3 | // 电器工厂接口
4 | public interface IElectricalFactory {
5 |
6 | IFan createFan();
7 |
8 | ITubeLight createTubeLight();
9 | }
10 |
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/src/main/java/io/spring2go/corespring/abstractfactory/IFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.abstractfactory;
2 |
3 | // 电扇接口
4 | public interface IFan {
5 |
6 | public void swithOn();
7 |
8 | public void switchOff();
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/src/main/java/io/spring2go/corespring/abstractfactory/ITubeLight.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.abstractfactory;
2 |
3 | // 日光灯接口
4 | public interface ITubeLight {
5 | public void swithOn();
6 |
7 | public void switchOff();
8 |
9 | public void tuneLight();
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/src/main/java/io/spring2go/corespring/abstractfactory/USElectricalFactory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.abstractfactory;
2 |
3 | public class USElectricalFactory implements IElectricalFactory {
4 |
5 | public IFan createFan() {
6 | return new USFan();
7 | }
8 |
9 | public ITubeLight createTubeLight() {
10 | return new USTubeLight();
11 | }
12 |
13 | }
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/src/main/java/io/spring2go/corespring/abstractfactory/USFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.abstractfactory;
2 |
3 | public class USFan implements IFan {
4 |
5 | public void swithOn() {
6 | System.out.println("The USFan is swithed on ...");
7 | }
8 |
9 | public void switchOff() {
10 | System.out.println("The USFan is swithed off ...");
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/patterns/creation/abstract-factory/src/main/java/io/spring2go/corespring/abstractfactory/USTubeLight.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.abstractfactory;
2 |
3 | public class USTubeLight implements ITubeLight {
4 | public void swithOn() {
5 | System.out.println("The USTubeLight is swithed on ...");
6 | }
7 |
8 | public void switchOff() {
9 | System.out.println("The USTubeLight is swithed off ...");
10 | }
11 |
12 | public void tuneLight() {
13 | System.out.println("The USTubeLight is tuned ...");
14 | }
15 | }
--------------------------------------------------------------------------------
/patterns/creation/builder/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Builder
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 |
10 | UTF-8
11 | UTF-8
12 | 1.8
13 | 1.8
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/classicbuilder/AndroidPhoneBuilder.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.classicbuilder;
2 |
3 | // 安卓手机具体构建者"ConcreteBuilder"
4 | public class AndroidPhoneBuilder implements IMobilePhoneBuilder {
5 |
6 | private MobilePhone phone;
7 |
8 | public AndroidPhoneBuilder() {
9 | this.phone = new MobilePhone("Android Phone");
10 | }
11 |
12 | @Override
13 | public void buildScreen() {
14 | phone.setPhoneScreen(ScreenType.SCREENTYPE_TOUCH_RESISTIVE);
15 | }
16 |
17 | @Override
18 | public void buildBattery() {
19 | phone.setPhoneBattery(Battery.MAH_1500);
20 | }
21 |
22 | @Override
23 | public void buildOS() {
24 | phone.setPhoneOS(OperatingSystem.ANDROID);
25 | }
26 |
27 | @Override
28 | public void buildStylus() {
29 | phone.setPhoneStylus(Stylus.YES);
30 | }
31 |
32 | // 获得最终构建出来的产品
33 | @Override
34 | public MobilePhone getPhone() {
35 | return this.phone;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/classicbuilder/Battery.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.classicbuilder;
2 |
3 | // 电池容量
4 | public enum Battery {
5 | MAH_1000,
6 | MAH_1500,
7 | MAH_2000
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/classicbuilder/ClassicBuilderMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.classicbuilder;
2 |
3 | // 客户程序
4 | public class ClassicBuilderMain {
5 |
6 | public static void main(String[] args) {
7 | // 先创建导演Director
8 | Manufacturer manufacturer = new Manufacturer();
9 | // 先准备Builder接口
10 | IMobilePhoneBuilder phoneBuilder = null;
11 |
12 | // 制造一部安卓手机
13 | phoneBuilder = new AndroidPhoneBuilder();
14 | manufacturer.construct(phoneBuilder);
15 | String output = String.format("A new Phone built:\n\n%s", phoneBuilder.getPhone().toString());
16 | System.out.println(output);
17 |
18 | // 制造一部Windows手机
19 | phoneBuilder = new WindowsPhoneBuilder();
20 | manufacturer.construct(phoneBuilder);
21 | output = String.format("A new Phone built:\n\n%s", phoneBuilder.getPhone().toString());
22 | System.out.println(output);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/classicbuilder/IMobilePhoneBuilder.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.classicbuilder;
2 |
3 | // 这个是构建者"Builder"接口
4 | public interface IMobilePhoneBuilder {
5 | void buildScreen();
6 | void buildBattery();
7 | void buildOS();
8 | void buildStylus();
9 | MobilePhone getPhone();
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/classicbuilder/Manufacturer.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.classicbuilder;
2 |
3 | // 这个是导演"Director"
4 | public class Manufacturer {
5 | public void construct(IMobilePhoneBuilder phoneBuilder) {
6 | phoneBuilder.buildBattery();
7 | phoneBuilder.buildOS();
8 | phoneBuilder.buildScreen();
9 | phoneBuilder.buildStylus();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/classicbuilder/MobilePhone.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.classicbuilder;
2 |
3 | // 这是"Product"产品类
4 | public class MobilePhone {
5 | // 部件类型
6 | private String phoneName;
7 | private ScreenType phoneScreen;
8 | private Battery phoneBattery;
9 | private OperatingSystem phoneOS;
10 | private Stylus phoneStylus;
11 |
12 | // region 访问手机组件的getter/setter公开方法
13 | public MobilePhone(String name) {
14 | this.phoneName = name;
15 | }
16 |
17 | public String getPhoneName() {
18 | return phoneName;
19 | }
20 |
21 | public ScreenType getPhoneScreen() {
22 | return phoneScreen;
23 | }
24 |
25 | public void setPhoneScreen(ScreenType phoneScreen) {
26 | this.phoneScreen = phoneScreen;
27 | }
28 |
29 | public Battery getPhoneBattery() {
30 | return phoneBattery;
31 | }
32 |
33 | public void setPhoneBattery(Battery phoneBattery) {
34 | this.phoneBattery = phoneBattery;
35 | }
36 |
37 | public OperatingSystem getPhoneOS() {
38 | return phoneOS;
39 | }
40 |
41 | public void setPhoneOS(OperatingSystem phoneOS) {
42 | this.phoneOS = phoneOS;
43 | }
44 |
45 | public Stylus getPhoneStylus() {
46 | return phoneStylus;
47 | }
48 |
49 | public void setPhoneStylus(Stylus phoneStylus) {
50 | this.phoneStylus = phoneStylus;
51 | }
52 | // endregion
53 |
54 | @Override
55 | public String toString() {
56 | return String.format("Name: %s\nScreen: %s\nBattery: %s\nOS: %s\nStylus: %s\n", this.phoneName,
57 | this.phoneScreen, this.phoneBattery, this.phoneOS, this.phoneStylus);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/classicbuilder/OperatingSystem.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.classicbuilder;
2 |
3 | // 操作系统
4 | public enum OperatingSystem {
5 | ANDROID,
6 | WINDOWS_MOBILE,
7 | WINDOWS_PHONE,
8 | SYMBIAN
9 | }
10 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/classicbuilder/ScreenType.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.classicbuilder;
2 |
3 | // 屏幕类型
4 | public enum ScreenType {
5 | SCREENTYPE_TOUCH_CAPACITIVE, // 电容式
6 | SCREENTYPE_TOUCH_RESISTIVE, // 电阻式
7 | SCREENTYPE_NON_TOUCH
8 | }
9 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/classicbuilder/Stylus.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.classicbuilder;
2 |
3 | // 触控笔
4 | public enum Stylus {
5 | YES,
6 | NO
7 | }
8 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/classicbuilder/WindowsPhoneBuilder.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.classicbuilder;
2 |
3 | // Windows手机具体构建者"ConcreteBuilder"
4 | public class WindowsPhoneBuilder implements IMobilePhoneBuilder {
5 |
6 | private MobilePhone phone;
7 |
8 | public WindowsPhoneBuilder() {
9 | this.phone = new MobilePhone("Windows Phone");
10 | }
11 |
12 | @Override
13 | public void buildScreen() {
14 | phone.setPhoneScreen(ScreenType.SCREENTYPE_TOUCH_CAPACITIVE);
15 | }
16 |
17 | @Override
18 | public void buildBattery() {
19 | phone.setPhoneBattery(Battery.MAH_2000);
20 | }
21 |
22 | @Override
23 | public void buildOS() {
24 | phone.setPhoneOS(OperatingSystem.WINDOWS_PHONE);
25 | }
26 |
27 | @Override
28 | public void buildStylus() {
29 | phone.setPhoneStylus(Stylus.NO);
30 | }
31 |
32 | @Override
33 | public MobilePhone getPhone() {
34 | return this.phone;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/javabean/JavaBeanMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.javabean;
2 |
3 | public class JavaBeanMain {
4 |
5 | // JavaBean构造对象
6 | public static void main(String[] args) {
7 | User user = new User();
8 | user.setFirstName("william");
9 | user.setLastName("yang");
10 | user.setAge(35);
11 | user.setPhone("18001756666");
12 | user.setAddress("shanghai pudong");
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/javabean/User.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.javabean;
2 |
3 | // JavaBeans模式
4 | public class User {
5 |
6 | //region 私有成员
7 | private String firstName;
8 | private String lastName;
9 | private int age;
10 | private String phone;
11 | private String address;
12 | //endregion
13 |
14 | public User() {}
15 |
16 | public String getFirstName() {
17 | return firstName;
18 | }
19 | public void setFirstName(String firstName) {
20 | this.firstName = firstName;
21 | }
22 | public String getLastName() {
23 | return lastName;
24 | }
25 | public void setLastName(String lastName) {
26 | this.lastName = lastName;
27 | }
28 | public int getAge() {
29 | return age;
30 | }
31 | public void setAge(int age) {
32 | this.age = age;
33 | }
34 | public String getPhone() {
35 | return phone;
36 | }
37 | public void setPhone(String phone) {
38 | this.phone = phone;
39 | }
40 | public String getAddress() {
41 | return address;
42 | }
43 | public void setAddress(String address) {
44 | this.address = address;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/modernbuilder/ModernBuilderMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.modernbuilder;
2 |
3 | public class ModernBuilderMain {
4 |
5 | public static void main(String[] args) {
6 | User user1 = new User.UserBuilder("william", "Yang")
7 | .age(35)
8 | .phone("123456")
9 | .address("Fake address 1234")
10 | .build();
11 |
12 | System.out.println(user1);
13 |
14 | User user2 = new User.UserBuilder("Jack", "Liu")
15 | .age(40)
16 | .phone("5655")
17 | //no address
18 | .build();
19 |
20 | System.out.println(user2);
21 |
22 | User user3 = new User.UserBuilder("Frank", "Han")
23 | //no age
24 | //no phone
25 | //no address
26 | .build();
27 |
28 | System.out.println(user3);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/modernbuilder/User.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.modernbuilder;
2 |
3 | // 流畅接口(Fluent Interface)
4 | public class User {
5 | // 所有字段final
6 | private final String firstName; // 必须
7 | private final String lastName; // 必须
8 | private final int age; // 可选
9 | private final String phone; // 可选
10 | private final String address; // 可选
11 |
12 | private User(UserBuilder builder) {
13 | this.firstName = builder.firstName;
14 | this.lastName = builder.lastName;
15 | this.age = builder.age;
16 | this.phone = builder.phone;
17 | this.address = builder.address;
18 | }
19 |
20 | // 全部是getter,没有setter,保证不可变性immutability
21 | public String getFirstName() {
22 | return firstName;
23 | }
24 |
25 | public String getLastName() {
26 | return lastName;
27 | }
28 |
29 | public int getAge() {
30 | return age;
31 | }
32 |
33 | public String getPhone() {
34 | return phone;
35 | }
36 |
37 | public String getAddress() {
38 | return address;
39 | }
40 |
41 | @Override
42 | public String toString() {
43 | return "User: " + this.firstName + ", "
44 | + this.lastName + ", " + this.age + ", "
45 | + this.phone + ", " + this.address;
46 | }
47 |
48 | public static class UserBuilder {
49 | private final String firstName;
50 | private final String lastName;
51 | private int age;
52 | private String phone;
53 | private String address;
54 |
55 | public UserBuilder(String firstName, String lastName) {
56 | this.firstName = firstName;
57 | this.lastName = lastName;
58 | }
59 |
60 | public UserBuilder age(int age) {
61 | this.age = age;
62 | return this;
63 | }
64 |
65 | public UserBuilder phone(String phone) {
66 | this.phone = phone;
67 | return this;
68 | }
69 |
70 | public UserBuilder address(String address) {
71 | this.address = address;
72 | return this;
73 | }
74 |
75 | // 返回最终构造的用户对象
76 | public User build() {
77 | User user = new User(this);
78 | validateUserObject(user);
79 | return user;
80 | }
81 |
82 | private void validateUserObject(User user) {
83 | // 基本的验证检查
84 | // 确保用户对象不违反系统假设
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/patterns/creation/builder/src/main/java/io/spring2go/corespring/telescoping_constructor/User.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.telescoping_constructor;
2 |
3 | // 显微镜构造函数模式
4 | public class User {
5 |
6 | // region 私有成员
7 | private String firstName;
8 | private String lastName;
9 | private int age;
10 | private String phone;
11 | private String address;
12 | // endregion
13 |
14 | public User(String firstName, String lastName, int age, String phone) {
15 | this.firstName = firstName;
16 | this.lastName = lastName;
17 | this.age = age;
18 | this.phone = phone;
19 | }
20 |
21 | public User(String firstName, String lastName, String phone, String address) {
22 | this.firstName = firstName;
23 | this.lastName = lastName;
24 | this.phone = phone;
25 | this.address = address;
26 | }
27 |
28 | public User(String firstName, String lastName, int age) {
29 | this.firstName = firstName;
30 | this.lastName = lastName;
31 | this.age = age;
32 | }
33 |
34 | public User(String firstName, String lastName) {
35 | this.firstName = firstName;
36 | this.lastName = lastName;
37 | }
38 |
39 | // region public getter
40 | public String getFirstName() {
41 | return firstName;
42 | }
43 |
44 | public String getLastName() {
45 | return lastName;
46 | }
47 |
48 | public int getAge() {
49 | return age;
50 | }
51 |
52 | public String getPhone() {
53 | return phone;
54 | }
55 |
56 | public String getAddress() {
57 | return address;
58 | }
59 | // endregion
60 | }
61 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | FactoryMethod
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/CeilingFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | // 吊扇
4 | public class CeilingFan implements IFan {
5 |
6 | @Override
7 | public void swithOn() {
8 | System.out.println("The CeilingFan is swithed on ...");
9 | }
10 |
11 | @Override
12 | public void switchOff() {
13 | System.out.println("The CeilingFan is swithed off ...");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/CeilingFanFactory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | public class CeilingFanFactory implements IFanFactory {
4 |
5 | @Override
6 | public IFan createFan() {
7 | return new CeilingFan();
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/ExhaustFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | public class ExhaustFan implements IFan {
4 |
5 | @Override
6 | public void swithOn() {
7 | System.out.println("The ExhaustFan is swithed on ...");
8 | }
9 |
10 | @Override
11 | public void switchOff() {
12 | System.out.println("The ExhaustFan is swithed off ...");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/ExhaustFanFactory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | public class ExhaustFanFactory implements IFanFactory {
4 |
5 | @Override
6 | public IFan createFan() {
7 | return new ExhaustFan();
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/FactoryMethodMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | //客户端代码
4 | public class FactoryMethodMain {
5 |
6 | public static void main(String[] args) {
7 | IFanFactory fanFactory = new PropellerFanFactory();
8 |
9 | // 使用工厂方法创建一个电扇
10 | IFan fan = fanFactory.createFan();
11 |
12 | // 使用创建的对象
13 | fan.swithOn();
14 |
15 | fan.switchOff();
16 | }
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/IFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | public interface IFan {
4 |
5 | public void swithOn();
6 |
7 | public void switchOff();
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/IFanFactory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | public interface IFanFactory {
4 | IFan createFan();
5 | }
6 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/PropellerFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | // 螺旋桨式通风扇
4 | public class PropellerFan implements IFan {
5 |
6 | @Override
7 | public void swithOn() {
8 | System.out.println("The PropellerFan is swithed on ...");
9 | }
10 |
11 | @Override
12 | public void switchOff() {
13 | System.out.println("The PropellerFan is swithed off ...");
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/PropellerFanFactory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | public class PropellerFanFactory implements IFanFactory {
4 |
5 | @Override
6 | public IFan createFan() {
7 | return new PropellerFan();
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/TableFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | // 台扇
4 | public class TableFan implements IFan {
5 |
6 | @Override
7 | public void swithOn() {
8 | System.out.println("The TableFan is swithed on ...");
9 | }
10 |
11 | @Override
12 | public void switchOff() {
13 | System.out.println("The TableFan is swithed off ...");
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/patterns/creation/factory-method/src/main/java/io/spring2go/corespring/factorymethod/TableFanFactory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.factorymethod;
2 |
3 | public class TableFanFactory implements IFanFactory {
4 |
5 | @Override
6 | public IFan createFan() {
7 | return new TableFan();
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/creation/simple-factory/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | SimpleFactory
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/creation/simple-factory/src/main/java/io/spring2go/corespring/nofactory/NoFactoryMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.nofactory;
2 |
3 | public class NoFactoryMain {
4 |
5 | public static void main(String[] args) {
6 | TableFan fan = new TableFan();
7 | fan.switchOn();
8 | }
9 |
10 | }
11 |
12 | class TableFan {
13 | public void switchOn() {
14 | System.out.println("The TableFan is switched on ...");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/patterns/creation/simple-factory/src/main/java/io/spring2go/corespring/simplefactory/CeilingFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.simplefactory;
2 |
3 | public class CeilingFan implements IFan {
4 |
5 | @Override
6 | public void swithOn() {
7 | System.out.println("The CeilingFan is swithed on ...");
8 | }
9 |
10 | @Override
11 | public void switchOff() {
12 | System.out.println("The CeilingFan is swithed off ...");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/patterns/creation/simple-factory/src/main/java/io/spring2go/corespring/simplefactory/ExhaustFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.simplefactory;
2 |
3 | public class ExhaustFan implements IFan {
4 |
5 | @Override
6 | public void swithOn() {
7 | System.out.println("The ExhaustFan is swithed on ...");
8 | }
9 |
10 | @Override
11 | public void switchOff() {
12 | System.out.println("The ExhaustFan is swithed off ...");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/patterns/creation/simple-factory/src/main/java/io/spring2go/corespring/simplefactory/FanFactory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.simplefactory;
2 |
3 | public class FanFactory implements IFanFactory {
4 |
5 | @Override
6 | public IFan createFan(FanType type) {
7 | switch (type) {
8 | case TableFan:
9 | return new TableFan();
10 | case CeilingFan:
11 | return new CeilingFan();
12 | case ExhaustFan:
13 | return new ExhaustFan();
14 | default:
15 | return new TableFan();
16 | }
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/patterns/creation/simple-factory/src/main/java/io/spring2go/corespring/simplefactory/FanType.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.simplefactory;
2 |
3 | public enum FanType {
4 |
5 | TableFan, //台扇
6 | CeilingFan, //吊扇
7 | ExhaustFan // 排风扇
8 | }
9 |
--------------------------------------------------------------------------------
/patterns/creation/simple-factory/src/main/java/io/spring2go/corespring/simplefactory/IFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.simplefactory;
2 |
3 | public interface IFan {
4 |
5 | public void swithOn();
6 |
7 | public void switchOff();
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/patterns/creation/simple-factory/src/main/java/io/spring2go/corespring/simplefactory/IFanFactory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.simplefactory;
2 |
3 | public interface IFanFactory {
4 | IFan createFan(FanType type);
5 | }
6 |
--------------------------------------------------------------------------------
/patterns/creation/simple-factory/src/main/java/io/spring2go/corespring/simplefactory/SimpleFactoryMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.simplefactory;
2 |
3 | // 客户端代码
4 | public class SimpleFactoryMain {
5 |
6 | public static void main(String[] args) {
7 | IFanFactory simpleFactory = new FanFactory();
8 | // 使用简单工厂创建一个电扇
9 | IFan fan = simpleFactory.createFan(FanType.TableFan);
10 | fan.swithOn();
11 | fan.switchOff();
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/patterns/creation/simple-factory/src/main/java/io/spring2go/corespring/simplefactory/TableFan.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.simplefactory;
2 |
3 | public class TableFan implements IFan {
4 |
5 | @Override
6 | public void swithOn() {
7 | System.out.println("The TableFan is swithed on ...");
8 | }
9 |
10 | @Override
11 | public void switchOff() {
12 | System.out.println("The TableFan is swithed off ...");
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/patterns/creation/singleton/filename.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/patterns/creation/singleton/filename.ser
--------------------------------------------------------------------------------
/patterns/creation/singleton/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Singleton
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton/v3/BillPughSingleton.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton.v3;
2 |
3 | // 比尔.普夫单例
4 | public class BillPughSingleton {
5 | // 私有构造函数,避免被客户端代码使用
6 | private BillPughSingleton() {}
7 |
8 | private static class LazyHolder {
9 | private static final BillPughSingleton INSTANCE = new BillPughSingleton();
10 | }
11 |
12 | public static BillPughSingleton getInstance() {
13 | return LazyHolder.INSTANCE;
14 | }
15 | }
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton/v4/EnumSingleton.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton.v4;
2 |
3 | // 枚举单例
4 | public enum EnumSingleton {
5 | INSTANCE;
6 |
7 | // 添加单例方法
8 | public void method() {
9 | System.out.println("Singleton method called...");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton/v4/TestEnumSingleton.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton.v4;
2 |
3 | public class TestEnumSingleton {
4 |
5 | public static void main(String[] args) {
6 | EnumSingleton.INSTANCE.method();
7 | }
8 |
9 | }
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton_deserialization/DemoSingleton.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton_deserialization;
2 |
3 | import java.io.Serializable;
4 |
5 | public class DemoSingleton implements Serializable {
6 | private static final long serialVersionUID = -7604766932017737115L;
7 |
8 | private static class LazyHolder{
9 | private static final DemoSingleton INSTANCE = new DemoSingleton();
10 | }
11 |
12 | public static DemoSingleton getInstance(){
13 | return LazyHolder.INSTANCE;
14 | }
15 |
16 | // 确保反序列化单例
17 | protected Object readResolve() {
18 | return getInstance();
19 | }
20 | }
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton_deserialization/SerializationTest.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton_deserialization;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.FileNotFoundException;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.io.ObjectInput;
8 | import java.io.ObjectInputStream;
9 | import java.io.ObjectOutput;
10 | import java.io.ObjectOutputStream;
11 |
12 | public class SerializationTest {
13 |
14 | public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
15 | DemoSingleton instanceOne = DemoSingleton.getInstance();
16 | ObjectOutput out = new ObjectOutputStream(new FileOutputStream(
17 | "filename.ser"));
18 | out.writeObject(instanceOne);
19 | out.close();
20 |
21 | // 从文件反序列化到对象
22 | ObjectInput in = new ObjectInputStream(new FileInputStream(
23 | "filename.ser"));
24 | DemoSingleton instanceTwo = (DemoSingleton) in.readObject();
25 | in.close();
26 |
27 | System.out.println("instanceOne hashCode="+instanceOne.hashCode());
28 | System.out.println("instanceTwo hashCode="+instanceTwo.hashCode());
29 |
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton_reflection/ReflectionSingleton.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton_reflection;
2 |
3 | public class ReflectionSingleton {
4 | private static ReflectionSingleton INSTANCE;
5 |
6 | private ReflectionSingleton() {
7 | //throw new InstantiationError("不能通过反射创建单例");
8 | }
9 |
10 | public static synchronized ReflectionSingleton getInstance() {
11 | if (INSTANCE == null) {
12 | INSTANCE = new ReflectionSingleton();
13 | }
14 | return INSTANCE;
15 | }
16 | }
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton_reflection/ReflectionTest.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton_reflection;
2 |
3 | import java.lang.reflect.Constructor;
4 |
5 | public class ReflectionTest {
6 |
7 | public static void main(String[] args) {
8 | ReflectionSingleton instanceOne = ReflectionSingleton.getInstance();
9 | ReflectionSingleton instanceTwo = null;
10 | try {
11 | Constructor constructor = ReflectionSingleton.class.getDeclaredConstructor();
12 | // 下面的代码会破坏单例
13 | constructor.setAccessible(true);
14 | // 创建第二个实例
15 | instanceTwo = (ReflectionSingleton) constructor.newInstance();
16 | } catch (Exception e) {
17 | e.printStackTrace();
18 | }
19 | System.out.println(instanceOne.hashCode());
20 | System.out.println(instanceTwo.hashCode());
21 | }
22 | }
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton_v1/EagerSingleton.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton_v1;
2 |
3 | // 提前初始化单例
4 | public class EagerSingleton {
5 | private static final EagerSingleton INSTANCE = new EagerSingleton();
6 |
7 | // 私有构造函数,避免被客户端代码使用
8 | private EagerSingleton() {}
9 |
10 | public static EagerSingleton getInstance() {
11 | return INSTANCE;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton_v1_1/StaticBlockSingleton.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton_v1_1;
2 |
3 | // 静态初始化块单例
4 | public class StaticBlockSingleton {
5 | private static final StaticBlockSingleton INSTANCE;
6 |
7 | // 私有构造函数,避免被客户端使用
8 | private StaticBlockSingleton() {}
9 |
10 | static {
11 | try {
12 | INSTANCE = new StaticBlockSingleton();
13 | } catch (Exception e) { // 异常处理
14 | throw new RuntimeException("Uffff, i was not expecting this!", e);
15 | }
16 | }
17 |
18 | public static StaticBlockSingleton getInstance() {
19 | return INSTANCE;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton_v2/LazySingleton.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton_v2;
2 |
3 | // 延迟初始化单例
4 | public class LazySingleton {
5 | private static LazySingleton INSTANCE;
6 |
7 | private LazySingleton(){}
8 |
9 | public static LazySingleton getInstance(){
10 | if(INSTANCE == null){
11 | INSTANCE = new LazySingleton();
12 | }
13 | return INSTANCE;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton_v2_1/ThreadSafeSingleton.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton_v2_1/ThreadSafeSingleton.java
--------------------------------------------------------------------------------
/patterns/creation/singleton/src/main/java/io/spring2go/corespring/singleton_v2_2/DoubleCheckLockingSingleton.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.singleton_v2_2;
2 |
3 | // 双重检查锁定单例
4 | public class DoubleCheckLockingSingleton {
5 | private static volatile DoubleCheckLockingSingleton INSTANCE;
6 |
7 | // 私有构造函数,避免被客户端代码使用
8 | private DoubleCheckLockingSingleton() {}
9 |
10 | public static DoubleCheckLockingSingleton getInstance() {
11 | if (INSTANCE == null) {
12 | synchronized (DoubleCheckLockingSingleton.class) {
13 | // 双重检查
14 | if (INSTANCE == null) {
15 | INSTANCE = new DoubleCheckLockingSingleton();
16 | }
17 | }
18 | }
19 | return INSTANCE;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/patterns/general/dependency-inversion/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | DependencyInversion
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/general/dependency-inversion/src/main/java/io/spring2go/corespring/injection/AppMonitorConstructorInjection.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.injection;
2 |
3 | import io.spring2go.corespring.ioc.EventLogWriter;
4 | import io.spring2go.corespring.ioc.INotifier;
5 |
6 | public class AppMonitorConstructorInjection {
7 | // 事件通知器
8 | private INotifier notifier = null;
9 |
10 | public AppMonitorConstructorInjection(INotifier notifier) {
11 | this.notifier = notifier;
12 | }
13 |
14 | // 应用有问题时该方法被调用
15 | public void notify(String message) {
16 | notifier.notify(message);
17 | }
18 |
19 | public static void main(String[] args) {
20 | EventLogWriter writer = new EventLogWriter();
21 | AppMonitorConstructorInjection monitor =
22 | new AppMonitorConstructorInjection(writer);
23 | monitor.notify("App has a problem ...");
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/patterns/general/dependency-inversion/src/main/java/io/spring2go/corespring/injection/AppMonitorSetterInjection.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.injection;
2 |
3 | import io.spring2go.corespring.ioc.EventLogWriter;
4 | import io.spring2go.corespring.ioc.INotifier;
5 |
6 | public class AppMonitorSetterInjection {
7 | // 事件通知器
8 | private INotifier notifier = null;
9 |
10 | public void SetNotifier(INotifier notifier) {
11 | this.notifier = notifier;
12 | }
13 |
14 | // 应用有问题时该方法被调用
15 | public void notify(String message) {
16 | notifier.notify(message);
17 | }
18 |
19 | public static void main(String[] args) {
20 | EventLogWriter writer = new EventLogWriter();
21 | AppMonitorSetterInjection monitor =
22 | new AppMonitorSetterInjection();
23 | // 可以在其它类中设置
24 | monitor.SetNotifier(writer);
25 | // 可以在其它类中调用
26 | monitor.notify("App has a problem ...");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/patterns/general/dependency-inversion/src/main/java/io/spring2go/corespring/ioc/AppMonitorIOC.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.ioc;
2 |
3 | public class AppMonitorIOC {
4 | // 事件通知器
5 | private INotifier notifier = null;
6 |
7 | // 应用有问题时该方法被调用
8 | public void notify(String message) {
9 | if (notifier == null) {
10 | // 将抽象接口映射到具体类
11 | notifier = new EventLogWriter();
12 | }
13 | notifier.notify(message);
14 | }
15 |
16 | public static void main(String[] args) {
17 | AppMonitorIOC appMonitor = new AppMonitorIOC();
18 | appMonitor.notify("App has a problem ...");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/patterns/general/dependency-inversion/src/main/java/io/spring2go/corespring/ioc/EmailSender.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.ioc;
2 |
3 | public class EmailSender implements INotifier {
4 |
5 | public void notify(String message) {
6 | // 发送Email
7 | System.out.println("Send email, message : " + message);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/general/dependency-inversion/src/main/java/io/spring2go/corespring/ioc/EventLogWriter.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.ioc;
2 |
3 | public class EventLogWriter implements INotifier {
4 |
5 | public void notify(String message) {
6 | // 写到事件日志
7 | System.out.println("Write to event log, message : " + message);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/general/dependency-inversion/src/main/java/io/spring2go/corespring/ioc/INotifier.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.ioc;
2 |
3 | // 事件通知器接口
4 | public interface INotifier {
5 | public void notify(String message);
6 | }
7 |
--------------------------------------------------------------------------------
/patterns/general/dependency-inversion/src/main/java/io/spring2go/corespring/ioc/SMSSender.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.ioc;
2 |
3 | public class SMSSender implements INotifier {
4 |
5 | public void notify(String message) {
6 | // 发送短消息
7 | System.out.println("Send SMS, message : " + message);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/patterns/general/dependency-inversion/src/main/java/io/spring2go/corespring/nodip/AppMonitorNoDIP.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.nodip;
2 |
3 | public class AppMonitorNoDIP {
4 |
5 | // 负责将事件日志写到日志系统
6 | private EventLogWriter writer = null;
7 |
8 | // 应用有问题时该方法将被调用
9 | public void notify(String message) {
10 | if (writer == null) {
11 | writer = new EventLogWriter();
12 | }
13 | writer.write(message);
14 | }
15 |
16 | public static void main(String[] args) {
17 | AppMonitorNoDIP appMonitor = new AppMonitorNoDIP();
18 | appMonitor.notify("App has a problem ...");
19 | }
20 | }
21 |
22 | class EventLogWriter {
23 |
24 | public void write(String message) {
25 | // 写到事件日志
26 | System.out.println("Write to event log, message : " + message);
27 | }
28 | }
29 |
30 |
31 |
--------------------------------------------------------------------------------
/patterns/structural/adapter/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Adapter
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/patterns/structural/adapter/src/main/java/io/spring2go/corespring/display/IHdmi.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.display;
2 |
3 | // HDMI接口
4 | public interface IHdmi {
5 |
6 | public void openHdmi();
7 | }
8 |
--------------------------------------------------------------------------------
/patterns/structural/adapter/src/main/java/io/spring2go/corespring/display/IVga.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.display;
2 |
3 | // VGA接口
4 | public interface IVga {
5 |
6 | public void openVga();
7 | }
8 |
--------------------------------------------------------------------------------
/patterns/structural/adapter/src/main/java/io/spring2go/corespring/display/LaptopMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.display;
2 |
3 | public class LaptopMain {
4 |
5 | public static void main(String[] args) {
6 |
7 | VgaDisplay vgaDisplay = new VgaDisplay();
8 |
9 | Vga2HdmiAdapter adapter = new Vga2HdmiAdapter(vgaDisplay);
10 |
11 | operateHdmiLaptop(adapter);
12 | }
13 |
14 | static void operateHdmiLaptop(IHdmi hdmiDisplay) {
15 | hdmiDisplay.openHdmi();
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/patterns/structural/adapter/src/main/java/io/spring2go/corespring/display/Vga2HdmiAdapter.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.display;
2 |
3 | // VGA2HDMI适配器
4 | public class Vga2HdmiAdapter implements IHdmi {
5 |
6 | private IVga vgaDisplay;
7 |
8 | public Vga2HdmiAdapter(IVga vgaDisplay) {
9 | this.vgaDisplay = vgaDisplay;
10 | }
11 |
12 | public void openHdmi() {
13 | // 适配逻辑
14 | this.vgaDisplay.openVga();
15 | System.out.println("Opening HDMI device");
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/patterns/structural/adapter/src/main/java/io/spring2go/corespring/display/VgaDisplay.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.display;
2 |
3 | // 支持VGA接口的显示器
4 | public class VgaDisplay implements IVga {
5 |
6 | public void openVga() {
7 | System.out.println("Opening..VGA Display...");
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/structural/adapter/src/main/java/io/spring2go/corespring/stack/ArrayStack.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/patterns/structural/adapter/src/main/java/io/spring2go/corespring/stack/ArrayStack.java
--------------------------------------------------------------------------------
/patterns/structural/adapter/src/main/java/io/spring2go/corespring/stack/ArrayStackMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.stack;
2 |
3 | public class ArrayStackMain {
4 |
5 | public static void main(String[] args) {
6 | ArrayStack stack = new ArrayStack(6);
7 |
8 | try {
9 | for(int i = 0; i < 6; i++) {
10 | stack.push(i);
11 | }
12 |
13 | System.out.println(stack);
14 |
15 | for(int i = 0; i < 5; i++) {
16 | stack.pop();
17 | }
18 |
19 | System.out.println(stack);
20 | } catch(StackException e) {
21 | System.err.println(e);
22 | }
23 |
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/patterns/structural/adapter/src/main/java/io/spring2go/corespring/stack/IStack.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/patterns/structural/adapter/src/main/java/io/spring2go/corespring/stack/IStack.java
--------------------------------------------------------------------------------
/patterns/structural/adapter/src/main/java/io/spring2go/corespring/stack/StackException.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.stack;
2 |
3 | public class StackException extends RuntimeException {
4 |
5 | private static final long serialVersionUID = 1L;
6 |
7 | public StackException(String name) {
8 | super(name);
9 | }
10 |
11 | public StackException() {
12 | super();
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/patterns/structural/bridge/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Bridge
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/Client.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge;
2 |
3 | public class Client {
4 |
5 | public static void main(String[] args) {
6 | String os = "linux";
7 | FileDownloaderAbstraction downloader = null;
8 |
9 | switch (os) {
10 | case "windows":
11 | downloader = new FileDownloaderAbstractionImpl(new WindowsFileDownloadImplementor());
12 | break;
13 | case "linux":
14 | downloader = new FileDownloaderAbstractionImpl(new LinuxFileDownloadImplementor());
15 | break;
16 |
17 | default:
18 | System.out.println("OS not supported !!");
19 | }
20 |
21 | Object fileContent = downloader.download("some path");
22 | downloader.store(fileContent);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/FileDownloadImplementor.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge;
2 |
3 | // Implementor
4 | public interface FileDownloadImplementor {
5 |
6 | public Object downloadFile(String path);
7 |
8 | public boolean storeFile(Object object);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/FileDownloaderAbstraction.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge;
2 |
3 | // Abstraction
4 | public interface FileDownloaderAbstraction {
5 |
6 | public Object download(String path);
7 |
8 | public boolean store(Object object);
9 | }
10 |
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/FileDownloaderAbstractionImpl.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge;
2 |
3 | // RefinedAbstraction
4 | public class FileDownloaderAbstractionImpl implements FileDownloaderAbstraction {
5 | private FileDownloadImplementor provider = null;
6 |
7 | public FileDownloaderAbstractionImpl(FileDownloadImplementor provider) {
8 | super();
9 | this.provider = provider;
10 | }
11 |
12 | @Override
13 | public Object download(String path) {
14 | return provider.downloadFile(path);
15 | }
16 |
17 | @Override
18 | public boolean store(Object path) {
19 | return provider.storeFile(path);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/LinuxFileDownloadImplementor.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge;
2 |
3 | // Concrete Implementor
4 | public class LinuxFileDownloadImplementor implements FileDownloadImplementor {
5 |
6 | @Override
7 | public Object downloadFile(String path) {
8 | return new Object();
9 | }
10 |
11 | @Override
12 | public boolean storeFile(Object object) {
13 | System.out.println("File download successfully in LINUX !!");
14 | return true;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/WindowsFileDownloadImplementor.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge;
2 |
3 | //Concrete Implementor
4 | public class WindowsFileDownloadImplementor implements FileDownloadImplementor {
5 |
6 | @Override
7 | public Object downloadFile(String path) {
8 | return new Object();
9 | }
10 |
11 | @Override
12 | public boolean storeFile(Object object) {
13 | System.out.println("File download successfully in WINDOWS !!");
14 | return true;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/abstraction_change/FileDownloaderAbstraction.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge.abstraction_change;
2 |
3 | public interface FileDownloaderAbstraction {
4 | public Object download(String path);
5 |
6 | public boolean store(Object object);
7 |
8 | // 添加接口
9 | public boolean delete(String object);
10 | }
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/abstraction_change/FileDownloaderAbstractionImpl.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge.abstraction_change;
2 |
3 | import io.spring2go.corespring.bridge.FileDownloadImplementor;
4 | import io.spring2go.corespring.bridge.abstraction_change.FileDownloaderAbstraction;
5 |
6 | public class FileDownloaderAbstractionImpl implements FileDownloaderAbstraction {
7 |
8 | private FileDownloadImplementor provider = null;
9 |
10 | public FileDownloaderAbstractionImpl(FileDownloadImplementor provider) {
11 | super();
12 | this.provider = provider;
13 | }
14 |
15 | @Override
16 | public Object download(String path) {
17 | return provider.downloadFile(path);
18 | }
19 |
20 | @Override
21 | public boolean store(Object object) {
22 | return provider.storeFile(object);
23 | }
24 |
25 | @Override
26 | public boolean delete(String object) {
27 | return false;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/implementation_change/FileDownloadImplementor.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge.implementation_change;
2 |
3 | public interface FileDownloadImplementor {
4 | public Object downloadFile(String path);
5 |
6 | public boolean storeFile(Object object);
7 |
8 | // 增加接口
9 | public boolean delete(String object);
10 | }
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/implementation_change/LinuxFileDownloadImplementor.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge.implementation_change;
2 |
3 | public class LinuxFileDownloadImplementor implements FileDownloadImplementor {
4 | @Override
5 | public Object downloadFile(String path) {
6 | return new Object();
7 | }
8 |
9 | @Override
10 | public boolean storeFile(Object object) {
11 | System.out.println("File downloaded successfully in LINUX !!");
12 | return true;
13 | }
14 |
15 | @Override
16 | public boolean delete(String object) {
17 | return false;
18 | }
19 | }
--------------------------------------------------------------------------------
/patterns/structural/bridge/src/main/java/io/spring2go/corespring/bridge/implementation_change/WindowsFileDownloadImplementor.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.bridge.implementation_change;
2 |
3 | public class WindowsFileDownloadImplementor implements FileDownloadImplementor
4 | {
5 | @Override
6 | public Object downloadFile(String path) {
7 | return new Object();
8 | }
9 |
10 | @Override
11 | public boolean storeFile(Object object) {
12 | System.out.println("File downloaded successfully in LINUX !!");
13 | return true;
14 | }
15 |
16 | @Override
17 | public boolean delete(String object) {
18 | return false;
19 | }
20 | }
--------------------------------------------------------------------------------
/patterns/structural/composite/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go
5 | Composite
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_complex/BaseEmployee.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_complex;
2 |
3 | import java.util.List;
4 |
5 | public abstract class BaseEmployee implements IEmployee {
6 |
7 | protected String name;
8 | protected int employeeId;
9 | protected List subscriptions;
10 |
11 | @Override
12 | public String getName() {
13 | return this.name;
14 | }
15 |
16 | @Override
17 | public void setName(String name) {
18 | this.name = name;
19 | }
20 |
21 | @Override
22 | public int getEmployeeId() {
23 | return this.employeeId;
24 | }
25 |
26 | @Override
27 | public void setEmployeeId(int employeeId) {
28 | this.employeeId = employeeId;
29 | }
30 |
31 | @Override
32 | public List getSubscriptions() {
33 | return this.subscriptions;
34 | }
35 |
36 | @Override
37 | public void setSubscriptions(List subscriptions) {
38 | this.subscriptions = subscriptions;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_complex/CompanyMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_complex;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | public class CompanyMain {
7 |
8 | public static void main(String[] args) {
9 | // 创建一些开发者并赋予订购项
10 | IEmployee emp1 = new Developer("A", 1);
11 | List subs = Arrays.asList(Util.getIntellijSubscription(), Util.getJProfilierSubscription(),
12 | Util.getCSDNSubscription(), Util.getTrainingSubscription());
13 | emp1.setSubscriptions(subs);
14 |
15 | IEmployee emp2 = new Developer("B", 2);
16 | subs = Arrays.asList(Util.getIntellijSubscription(), Util.getJProfilierSubscription());
17 | emp2.setSubscriptions(subs);
18 |
19 | IEmployee emp3 = new Developer("C", 3);
20 | subs = Arrays.asList(Util.getIntellijSubscription());
21 | emp3.setSubscriptions(subs);
22 |
23 | IEmployee emp4 = new Developer("D", 4);
24 | subs = Arrays.asList(Util.getIntellijSubscription());
25 | emp4.setSubscriptions(subs);
26 |
27 | IEmployee emp5 = new Developer("E", 5);
28 | subs = Arrays.asList(Util.getIntellijSubscription());
29 | emp5.setSubscriptions(subs);
30 |
31 | IEmployee emp6 = new Developer("F", 6);
32 | subs = Arrays.asList(Util.getIntellijSubscription(), Util.getTrainingSubscription());
33 | emp6.setSubscriptions(subs);
34 |
35 | IEmployee emp7 = new Developer("G", 7);
36 | subs = Arrays.asList(Util.getIntellijSubscription());
37 | emp7.setSubscriptions(subs);
38 |
39 | IEmployee emp8 = new Developer("H", 8);
40 | subs = Arrays.asList(Util.getIntellijSubscription());
41 | emp8.setSubscriptions(subs);
42 |
43 | IEmployee emp9 = new Developer("I", 9);
44 | subs = Arrays.asList(Util.getIntellijSubscription());
45 | emp9.setSubscriptions(subs);
46 |
47 | IEmployee emp10 = new Developer("J", 10);
48 | subs = Arrays.asList(Util.getIntellijSubscription(), Util.getCSDNSubscription());
49 | emp10.setSubscriptions(subs);
50 |
51 | // 获取单个员工的成本细节
52 | System.out.println("Let's get cost details of single employee");
53 | Util.printCostDetails(emp1);
54 |
55 | // 获取一组员工的成本细节
56 | List employees = Arrays.asList(emp1, emp2, emp3, emp4, emp5, emp6, emp7, emp8, emp9, emp10);
57 | System.out.println("Let's check cost details of list of employees");
58 | for(IEmployee employee : employees) {
59 | Util.printCostDetails(employee);
60 | }
61 |
62 | // 设置经理
63 | subs = Arrays.asList(Util.getIntellijSubscription(), Util.getJProfilierSubscription(),
64 | Util.getCSDNSubscription(), Util.getTrainingSubscription());
65 | List teamMembers = Arrays.asList(emp1, emp2, emp3);
66 | IEmployee mng1 = new Manager("MA", 11, subs, teamMembers);
67 |
68 | subs = Arrays.asList(Util.getIntellijSubscription());
69 | teamMembers = Arrays.asList(emp4, emp5, emp6);
70 | IEmployee mng2 = new Manager("MB", 12, subs, teamMembers);
71 |
72 | subs = Arrays.asList(Util.getTrainingSubscription());
73 | teamMembers = Arrays.asList(emp7, emp8, emp9, emp10);
74 | IEmployee mng3 = new Manager("MC", 13, subs, teamMembers);
75 |
76 | // 获取单个经理的成本细节
77 | System.out.println("Let's get cost details of single manager");
78 | Util.printCostDetails(mng1);
79 |
80 | // 获取一组经理的成本细节
81 | System.out.println("Let's check details of list of manager");
82 | List managers = Arrays.asList(mng1, mng2, mng3);
83 | for(IEmployee employee : managers) {
84 | Util.printCostDetails(employee);
85 | }
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_complex/Developer.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_complex;
2 |
3 | // Leaf
4 | public class Developer extends BaseEmployee {
5 |
6 | public Developer(String name, int employeeId) {
7 | this.name = name;
8 | this.employeeId = employeeId;
9 | }
10 |
11 | public double getCost() {
12 | if (subscriptions== null)
13 | return 0;
14 | double cost = subscriptions.stream().mapToDouble(s -> s.getCost()).sum();
15 | return cost;
16 | }
17 |
18 | public int getSubscriptionCount(SubscriptionType type) {
19 | if (subscriptions == null)
20 | return 0;
21 | int count = (int) subscriptions.stream().filter(s -> s.getsType() == type).count();
22 | return count;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_complex/IEmployee.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_complex;
2 |
3 | import java.util.List;
4 |
5 | //Component
6 | public interface IEmployee {
7 | public String getName();
8 |
9 | public void setName(String name);
10 |
11 | public int getEmployeeId();
12 |
13 | public void setEmployeeId(int employeeId);
14 |
15 | public List getSubscriptions();
16 |
17 | public void setSubscriptions(List subscriptions);
18 |
19 | public double getCost();
20 |
21 | public int getSubscriptionCount(SubscriptionType type);
22 | }
23 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_complex/Manager.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_complex;
2 |
3 | import java.util.List;
4 |
5 | // Composite
6 | public class Manager extends BaseEmployee {
7 |
8 | private List teamMembers;
9 |
10 | public Manager(String name, int employeeId,
11 | List subscriptions,
12 | List teamMembers) {
13 | this.name = name;
14 | this.employeeId = employeeId;
15 | this.subscriptions = subscriptions;
16 | this.teamMembers = teamMembers;
17 | }
18 |
19 | public List getTeamMembers() {
20 | return teamMembers;
21 | }
22 |
23 | public void setTeamMembers(List teamMembers) {
24 | this.teamMembers = teamMembers;
25 | }
26 |
27 | @Override
28 | public double getCost() {
29 | double subsCost = 0.0;
30 | if (subscriptions != null) {
31 | subsCost = subscriptions.stream().mapToDouble(s -> s.getCost()).sum();
32 | }
33 |
34 | double membersCost = 0.0;
35 | if (teamMembers != null) {
36 | membersCost = teamMembers.stream().mapToDouble(m -> m.getCost()).sum();
37 | }
38 |
39 | return subsCost + membersCost;
40 | }
41 |
42 | @Override
43 | public int getSubscriptionCount(SubscriptionType type) {
44 | int subCount = 0;
45 | if (subscriptions != null) {
46 | subCount = (int) subscriptions.stream().filter(s -> s.getsType() == type).count();
47 | }
48 |
49 | int membersSubCount = 0;
50 | if (teamMembers != null) {
51 | for (IEmployee member: teamMembers) {
52 | List subs = member.getSubscriptions();
53 | if (subs != null) {
54 | for(Subscription sub : subs) {
55 | if (sub.getsType() == type) {
56 | membersSubCount++;
57 | }
58 | }
59 | }
60 | }
61 | }
62 |
63 | return subCount + membersSubCount;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_complex/Subscription.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_complex;
2 |
3 | public class Subscription {
4 | private SubscriptionType sType; // 订购类型
5 | private String name; // 名称
6 | private double cost; // 费用
7 |
8 | public SubscriptionType getsType() {
9 | return sType;
10 | }
11 | public void setsType(SubscriptionType sType) {
12 | this.sType = sType;
13 | }
14 | public String getName() {
15 | return name;
16 | }
17 | public void setName(String name) {
18 | this.name = name;
19 | }
20 | public double getCost() {
21 | return cost;
22 | }
23 | public void setCost(double cost) {
24 | this.cost = cost;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_complex/SubscriptionType.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_complex;
2 |
3 | public enum SubscriptionType {
4 | PRINT, // 打印
5 | SOFTWARE_LICENSE, // 软件License
6 | TRAINING; // 培训
7 | }
8 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_complex/Util.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_complex;
2 |
3 | public class Util {
4 |
5 | public static void printCostDetails(IEmployee employee) {
6 | double cost = employee.getCost();
7 | int licenseSubCount = employee.getSubscriptionCount(SubscriptionType.SOFTWARE_LICENSE);
8 | int printSubCount = employee.getSubscriptionCount(SubscriptionType.PRINT);
9 | int trainingSubCount = employee.getSubscriptionCount(SubscriptionType.TRAINING);
10 | String outMsg = "Cost: %f, Count License: %d, Count Print: %d, Count Training: %d, Emp ID: %d\n";
11 | System.out.print(String.format(outMsg, cost, licenseSubCount, printSubCount, trainingSubCount, employee.getEmployeeId()));
12 | }
13 |
14 | public static Subscription getIntellijSubscription() {
15 | Subscription sub = new Subscription();
16 | sub.setCost(30);
17 | sub.setName("Intellij License");
18 | sub.setsType(SubscriptionType.SOFTWARE_LICENSE);
19 | return sub;
20 | }
21 |
22 | public static Subscription getJProfilierSubscription() {
23 | Subscription sub = new Subscription();
24 | sub.setCost(20);
25 | sub.setName("JProfilier License");
26 | sub.setsType(SubscriptionType.SOFTWARE_LICENSE);
27 | return sub;
28 | }
29 |
30 | public static Subscription getCSDNSubscription() {
31 | Subscription sub = new Subscription();
32 | sub.setName("CSDN Magazine");
33 | sub.setsType(SubscriptionType.PRINT);
34 | sub.setCost(10);
35 | return sub;
36 | }
37 |
38 | public static Subscription getTrainingSubscription() {
39 | Subscription sub = new Subscription();
40 | sub.setName("Java Design Pattern");
41 | sub.setsType(SubscriptionType.TRAINING);
42 | sub.setCost(300);
43 | return sub;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_simple/CompositePatternMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_simple;
2 |
3 | // Client
4 | public class CompositePatternMain {
5 |
6 | public static void main(String[] args) {
7 | IEmployee emp1 = new Developer("John", 10000);
8 | IEmployee emp2 = new Developer("David", 15000);
9 | IEmployee manager1 = new Manager("Daniel", 25000);
10 | manager1.add(emp1);
11 | manager1.add(emp2);
12 | IEmployee emp3 = new Developer("Michael", 20000);
13 | Manager generalManager = new Manager("Mark", 50000);
14 | generalManager.add(emp3);
15 | generalManager.add(manager1);
16 | generalManager.print();
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_simple/Developer.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_simple;
2 |
3 | import io.spring2go.corespring.composite_simple.IEmployee;
4 |
5 | // leaf
6 | public class Developer implements IEmployee {
7 |
8 | private String name;
9 | private double salary;
10 |
11 | public Developer(String name, double salary) {
12 | this.name = name;
13 | this.salary = salary;
14 | }
15 |
16 | @Override
17 | public void add(IEmployee employee) {
18 | String msg = "not supported by leaf node.";
19 | throw new UnsupportedOperationException(msg);
20 | }
21 |
22 | @Override
23 | public void remove(IEmployee employee) {
24 | String msg = "not supported by leaf node.";
25 | throw new UnsupportedOperationException(msg);
26 | }
27 |
28 | @Override
29 | public IEmployee getChild(int i) {
30 | String msg = "not supported by leaf node.";;
31 | throw new UnsupportedOperationException(msg);
32 | }
33 |
34 | @Override
35 | public String getName() {
36 | return this.name;
37 | }
38 |
39 | @Override
40 | public double getSalary() {
41 | return this.salary;
42 | }
43 |
44 | @Override
45 | public void print() {
46 | System.out.println("-------------");
47 | System.out.println("Name ="+getName());
48 | System.out.println("Salary ="+getSalary());
49 | System.out.println("-------------");
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_simple/IEmployee.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_simple;
2 |
3 | // Component
4 | public interface IEmployee {
5 | public void add(IEmployee employee);
6 | public void remove(IEmployee employee);
7 | public IEmployee getChild(int i);
8 | public String getName();
9 | public double getSalary();
10 | public void print();
11 | }
12 |
--------------------------------------------------------------------------------
/patterns/structural/composite/src/main/java/io/spring2go/corespring/composite_simple/Manager.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.composite_simple;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | // Composite
7 | public class Manager implements IEmployee {
8 |
9 | private String name;
10 | private double salary;
11 | private List employees = new ArrayList();
12 |
13 | public Manager(String name, double salary) {
14 | this.name = name;
15 | this.salary = salary;
16 | }
17 |
18 | @Override
19 | public void add(IEmployee employee) {
20 | employees.add(employee);
21 | }
22 |
23 | @Override
24 | public void remove(IEmployee employee) {
25 | employees.remove(employee);
26 | }
27 |
28 | @Override
29 | public IEmployee getChild(int i) {
30 | return employees.get(i);
31 | }
32 |
33 | @Override
34 | public String getName() {
35 | return this.name;
36 | }
37 |
38 | @Override
39 | public double getSalary() {
40 | return this.salary;
41 | }
42 |
43 | @Override
44 | public void print() {
45 | System.out.println("-------------");
46 | System.out.println("Name =" + getName());
47 | System.out.println("Salary =" + getSalary());
48 | System.out.println("-------------");
49 |
50 | for(IEmployee employee : this.employees) {
51 | employee.print();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Decorator
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/ArtificialScentDecorator.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.decorator;
2 |
3 | //Concrete Decorator
4 | public class ArtificialScentDecorator extends Decorator {
5 |
6 | protected ArtificialScentDecorator(BakeryComponent baseComponent) {
7 | super(baseComponent);
8 | this.name = "Artificial Scent";
9 | this.price = 3.0;
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/BakeryComponent.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.decorator;
2 |
3 | // Component Interface
4 | public interface BakeryComponent {
5 |
6 | public String getName();
7 |
8 | public double getPrice();
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/CakeBase.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.decorator;
2 |
3 | // ConcreteComponent
4 | public class CakeBase implements BakeryComponent {
5 |
6 | private String name = "Cake Base";
7 | private double price = 200.0;
8 |
9 | @Override
10 | public String getName() {
11 | return this.name;
12 | }
13 |
14 | @Override
15 | public double getPrice() {
16 | return this.price;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/CherryDecorator.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.decorator;
2 |
3 | //Concrete Decorator
4 | public class CherryDecorator extends Decorator {
5 |
6 | protected CherryDecorator(BakeryComponent baseComponent) {
7 | super(baseComponent);
8 | this.name = "Cherry";
9 | this.price = 2.0;
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/CreamDecorator.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.decorator;
2 |
3 | // Concrete Decorator
4 | public class CreamDecorator extends Decorator {
5 |
6 | protected CreamDecorator(BakeryComponent baseComponent) {
7 | super(baseComponent);
8 | this.name = "Cream";
9 | this.price = 1.0;
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/Decorator.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.decorator;
2 |
3 | // Decorator
4 | public abstract class Decorator implements BakeryComponent {
5 |
6 | private BakeryComponent baseComponent = null;
7 |
8 | protected String name = "Undefined Decorator";
9 | protected double price = 0.0;
10 |
11 | protected Decorator(BakeryComponent baseComponent) {
12 | this.baseComponent = baseComponent;
13 | }
14 |
15 | @Override
16 | public String getName() {
17 | return this.baseComponent.getName() + ", " + this.name;
18 | }
19 |
20 | @Override
21 | public double getPrice() {
22 | return this.price + this.baseComponent.getPrice();
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/DecoratorMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.decorator;
2 |
3 | public class DecoratorMain {
4 |
5 | public static void main(String[] args) {
6 | // 先创建一个简单的Cake Base
7 | CakeBase cBase = new CakeBase();
8 | Util.printProductDetails(cBase);
9 |
10 | // 在蛋糕上添加奶油
11 | CreamDecorator creamCake = new CreamDecorator(cBase);
12 | Util.printProductDetails(creamCake);
13 |
14 | // 在蛋糕上添加樱桃
15 | CherryDecorator cherryCake = new CherryDecorator(creamCake);
16 | Util.printProductDetails(cherryCake);
17 |
18 | // 再添加香味
19 | ArtificialScentDecorator scentedCake =
20 | new ArtificialScentDecorator(cherryCake);
21 | Util.printProductDetails(scentedCake);
22 |
23 | // 最后在蛋糕上添加名片
24 | NameCardDecorator nameCardOnCake = new NameCardDecorator(scentedCake);
25 | Util.printProductDetails(nameCardOnCake);
26 |
27 | // 现在创建一个简单的糕点
28 | PastryBase pastry = new PastryBase();
29 | Util.printProductDetails(pastry);
30 |
31 | // 在糕点上只添加奶油和樱桃
32 | CreamDecorator creamPastry = new CreamDecorator(pastry);
33 | CherryDecorator cherryPastry = new CherryDecorator(creamPastry);
34 | Util.printProductDetails(cherryPastry);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/NameCardDecorator.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.decorator;
2 |
3 | //Concrete Decorator
4 | public class NameCardDecorator extends Decorator {
5 |
6 | protected NameCardDecorator(BakeryComponent baseComponent) {
7 | super(baseComponent);
8 | this.name = "Name Card";
9 | this.price = 4.0;
10 | }
11 |
12 | @Override
13 | public String getName() {
14 | return super.getName() +
15 | "(Please Collect your discount card for " +
16 | this.price +
17 | ")";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/PastryBase.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.decorator;
2 |
3 | // ConcreteComponent
4 | public class PastryBase implements BakeryComponent {
5 |
6 | private String name = "Pastry Base";
7 | private double price = 20.0;
8 |
9 | @Override
10 | public String getName() {
11 | return this.name;
12 | }
13 |
14 | @Override
15 | public double getPrice() {
16 | return this.price;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/Util.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.decorator;
2 |
3 | public class Util {
4 | public static void printProductDetails(BakeryComponent bComponent) {
5 | String out = "Item: " + bComponent.getName() + ", " + "Price: " + bComponent.getPrice();
6 | System.out.println(out);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/patterns/structural/decorator/src/main/java/io/spring2go/corespring/decorator/uml.ucls:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
10 |
11 |
12 |
13 |
14 |
16 |
17 |
19 |
20 |
21 |
22 |
23 |
26 |
27 |
29 |
30 |
31 |
32 |
33 |
36 |
37 |
39 |
40 |
41 |
42 |
43 |
46 |
47 |
49 |
50 |
51 |
52 |
53 |
56 |
57 |
59 |
60 |
61 |
62 |
63 |
66 |
67 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/patterns/structural/facade/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Facade
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/CostManager.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // 费用计算实现
4 | public class CostManager implements ICosting {
5 |
6 | @Override
7 | public float applyDiscount(float price, float discountPercent) {
8 | String out = String.format(
9 | "A discount of %f%% has been applied on the product's price of %f",
10 | discountPercent, price);
11 | System.out.println(out);
12 | return price - ((discountPercent / 100) * price);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/FacadeMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | public class FacadeMain {
4 |
5 | public static void main(String[] args) {
6 | // Creating the Order/Product details
7 | OrderDetails orderDetails = new OrderDetails("Java Design Pattern book",
8 | "Simplified book on design patterns in Java",
9 | 500, 10, "Street No 1", "Educational Area", 1212,
10 | "8811123456");
11 |
12 | // Using Facade
13 | OnlineShoppingFacade facade = new OnlineShoppingFacade();
14 | facade.finalizeOrder(orderDetails);
15 |
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/ICosting.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // 费用计算接口
4 | public interface ICosting {
5 | public float applyDiscount(float price, float discountPercent);
6 | }
7 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/IInventory.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // 库存接口
4 | public interface IInventory {
5 | public void update(int productId);
6 | }
7 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/ILogistics.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // 物流接口
4 | public interface ILogistics {
5 | public void shipProducts(String productName, String shippingAddress);
6 | }
7 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/IOrderVerify.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // 订单校验接口
4 | public interface IOrderVerify {
5 | public boolean verifyShippingAddress(int pincode);
6 | }
7 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/IPaymentGateway.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // 支付接口
4 | public interface IPaymentGateway {
5 | public boolean verifyCardDetails(String cardNo);
6 | public boolean processPayment(String cardNo, float cost);
7 | }
8 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/InventoryManager.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // 库存实现
4 | public class InventoryManager implements IInventory {
5 |
6 | @Override
7 | public void update(int productId) {
8 | String msg = "Product# " + productId +
9 | " is subtracted from store's inventory";
10 | System.out.println(msg);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/LogisticsManager.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // 物流实现
4 | public class LogisticsManager implements ILogistics {
5 |
6 | @Override
7 | public void shipProducts(String productName, String shippingAddress) {
8 | String out = String.format(
9 | "Congratulations your product %s has been shipped at the following address: %s.",
10 | productName, shippingAddress);
11 | System.out.println(out);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/NoFacadeMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // Client Code without Facade.
4 | public class NoFacadeMain {
5 |
6 | public static void main(String[] args) {
7 | // Creating the Order/Product details
8 | OrderDetails orderDetails = new OrderDetails("Java Design Pattern book",
9 | "Simplified book on design patterns in Java",
10 | 500, 10, "Street No 1", "Educational Area", 1212,
11 | "8811123456");
12 |
13 | // Updating the inventory.
14 | IInventory inventory = new InventoryManager();
15 | inventory.update(orderDetails.getProductNo());
16 |
17 | // verifying various details for the order such as the shipping address.
18 | IOrderVerify orderVerify = new OrderVerificationManager();
19 | orderVerify.verifyShippingAddress(orderDetails.getPinCode());
20 |
21 | // Calculating the final cost after applying various discounts.
22 | ICosting costManager = new CostManager();
23 | orderDetails.setPrice(
24 | costManager.applyDiscount(
25 | orderDetails.getPrice(),
26 | orderDetails.getDiscountPercent()
27 | )
28 | );
29 |
30 | // Going through various steps if payment gateway like card verification,
31 | // charging from the card.
32 | IPaymentGateway paymentGateway = new PaymentGatewayManager();
33 | paymentGateway.verifyCardDetails(orderDetails.getCardNo());
34 | paymentGateway.processPayment(orderDetails.getCardNo(), orderDetails.getPrice());
35 |
36 | // Completing the order by providing logistics.
37 | ILogistics logistics = new LogisticsManager();
38 | String shippingAddress = String.format("%s, %s - %d",
39 | orderDetails.getAddressLine1(),
40 | orderDetails.getAddressLine2(),
41 | orderDetails.getPinCode());
42 | logistics.shipProducts(orderDetails.getProductName(), shippingAddress);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/OnlineShoppingFacade.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | public class OnlineShoppingFacade {
4 | IInventory inventory = new InventoryManager();
5 | IOrderVerify orderVerify = new OrderVerificationManager();
6 | ICosting costManager = new CostManager();
7 | IPaymentGateway paymentGateway = new PaymentGatewayManager();
8 | ILogistics logistics = new LogisticsManager();
9 |
10 | public void finalizeOrder(OrderDetails orderDetails) {
11 | inventory.update(orderDetails.getProductNo());
12 | orderVerify.verifyShippingAddress(orderDetails.getPinCode());
13 | orderDetails.setPrice(
14 | costManager.applyDiscount(
15 | orderDetails.getPrice(),
16 | orderDetails.getDiscountPercent()
17 | )
18 | );
19 | paymentGateway.verifyCardDetails(orderDetails.getCardNo());
20 | paymentGateway.processPayment(orderDetails.getCardNo(), orderDetails.getPrice());
21 | String shippingAddress = String.format("%s, %s - %d",
22 | orderDetails.getAddressLine1(),
23 | orderDetails.getAddressLine2(),
24 | orderDetails.getPinCode());
25 | logistics.shipProducts(orderDetails.getCardNo(), shippingAddress);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/OrderDetails.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | import java.util.Random;
4 |
5 | public class OrderDetails {
6 | // region 私有成员
7 | private int productNo;
8 | private String productName;
9 | private String productDescription;
10 | private float price;
11 | private float discountPercent;
12 | private String addressLine1;
13 | private String addressLine2;
14 | private int pinCode;
15 | private String cardNo;
16 | // endregion
17 |
18 | public OrderDetails(String productName, String prodDescription, float price,
19 | float discount, String addressLine1, String addressLine2,
20 | int pinCode, String cardNo) {
21 | this.productNo = new Random(1).nextInt(100);
22 | this.productName = productName;
23 | this.productDescription = prodDescription;
24 | this.price = price;
25 | this.discountPercent = discount;
26 | this.addressLine1 = addressLine1;
27 | this.addressLine2 = addressLine2;
28 | this.pinCode = pinCode;
29 | this.cardNo = cardNo;
30 | }
31 |
32 | // region getters
33 | public int getProductNo() {
34 | return productNo;
35 | }
36 |
37 | public void setProductNo(int productNo) {
38 | this.productNo = productNo;
39 | }
40 |
41 | public String getProductName() {
42 | return productName;
43 | }
44 |
45 | public void setProductName(String productName) {
46 | this.productName = productName;
47 | }
48 |
49 | public String getProductDescription() {
50 | return productDescription;
51 | }
52 |
53 | public void setProductDescription(String productDescription) {
54 | this.productDescription = productDescription;
55 | }
56 |
57 | public float getPrice() {
58 | return price;
59 | }
60 |
61 | public void setPrice(float price) {
62 | this.price = price;
63 | }
64 |
65 | public float getDiscountPercent() {
66 | return discountPercent;
67 | }
68 |
69 | public void setDiscountPercent(float discountPercent) {
70 | this.discountPercent = discountPercent;
71 | }
72 |
73 | public String getAddressLine1() {
74 | return addressLine1;
75 | }
76 |
77 | public void setAddressLine1(String addressLine1) {
78 | this.addressLine1 = addressLine1;
79 | }
80 |
81 | public String getAddressLine2() {
82 | return addressLine2;
83 | }
84 |
85 | public void setAddressLine2(String addressLine2) {
86 | this.addressLine2 = addressLine2;
87 | }
88 |
89 | public int getPinCode() {
90 | return pinCode;
91 | }
92 |
93 | public void setPinCode(int pinCode) {
94 | this.pinCode = pinCode;
95 | }
96 |
97 | public String getCardNo() {
98 | return cardNo;
99 | }
100 |
101 | public void setCardNo(String cardNo) {
102 | this.cardNo = cardNo;
103 | }
104 | // endregion
105 | }
106 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/OrderVerificationManager.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // 订单校验实现
4 | public class OrderVerificationManager implements IOrderVerify {
5 |
6 | @Override
7 | public boolean verifyShippingAddress(int pincode) {
8 | System.out.println(
9 | "The product can be shipped to the pincode "
10 | + pincode);
11 | return true;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/patterns/structural/facade/src/main/java/io/spring2go/corespring/facade/PaymentGatewayManager.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring.facade;
2 |
3 | // 支付实现
4 | public class PaymentGatewayManager implements IPaymentGateway {
5 |
6 | @Override
7 | public boolean verifyCardDetails(String cardNo) {
8 | String out = "Card# " + cardNo +
9 | " has been verified and is accepted.";
10 | System.out.println(out);
11 | return true;
12 | }
13 |
14 | @Override
15 | public boolean processPayment(String cardNo, float cost) {
16 | String out = "Card# " + cardNo +
17 | " is used to make a payment of " + cost + ".";
18 | System.out.println(out);
19 | return true;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/patterns/structural/proxy/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | io.spring2go.corespring
5 | Proxy
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | UTF-8
10 | UTF-8
11 | 1.8
12 | 1.8
13 |
14 |
15 |
--------------------------------------------------------------------------------
/patterns/structural/proxy/src/main/java/io/spring2go/corespring/Folder.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | // RealSubject
4 | public class Folder implements IFolder {
5 |
6 | public void performOperations() {
7 | // access folder and perform various operations like copy or cut files
8 | System.out.println("Performing operation on folder");
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/patterns/structural/proxy/src/main/java/io/spring2go/corespring/FolderProxy.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | // Proxy
4 | public class FolderProxy implements IFolder {
5 |
6 | Folder folder;
7 | User user;
8 |
9 | public FolderProxy(User user) {
10 | this.user = user;
11 | }
12 |
13 | public void performOperations() {
14 | if (user.getUserName().equalsIgnoreCase("bobo") &&
15 | user.getPassword().equalsIgnoreCase("xyz")) {
16 | folder = new Folder();
17 | folder.performOperations();
18 | } else {
19 | System.out.println("You don't have access to this folder");
20 | }
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/patterns/structural/proxy/src/main/java/io/spring2go/corespring/IFolder.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | // Subject
4 | public interface IFolder {
5 |
6 | public void performOperations();
7 |
8 | }
--------------------------------------------------------------------------------
/patterns/structural/proxy/src/main/java/io/spring2go/corespring/ProxyDesignPatternMain.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | // Client
4 | public class ProxyDesignPatternMain {
5 |
6 | public static void main(String[] args) {
7 | // When you click on folder, Let's say a GUI form will ask for
8 | // usesrName and password.
9 | // and this GUI will create this user object
10 |
11 | // If we give correct userName and password
12 | User user = new User("bobo", "xyz");
13 | FolderProxy folderProxy = new FolderProxy(user);
14 | System.out.println("When userName and password are correct:");
15 | folderProxy.performOperations();
16 | System.out.println("**************************************");
17 | // if we give wrong userName and Password
18 | User userWrong = new User("abc", "abc");
19 | FolderProxy folderProxyWrong = new FolderProxy(userWrong);
20 | System.out.println("When userName and password are incorrect");
21 | folderProxyWrong.performOperations();
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/patterns/structural/proxy/src/main/java/io/spring2go/corespring/User.java:
--------------------------------------------------------------------------------
1 | package io.spring2go.corespring;
2 |
3 | public class User {
4 |
5 | String username;
6 | String password;
7 |
8 | public User(String username, String password) {
9 | this.username = username;
10 | this.password = password;
11 | }
12 |
13 | public String getUserName() {
14 | return this.username;
15 | }
16 |
17 | public String getPassword() {
18 | return this.password;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/patterns/structural/proxy/src/main/java/io/spring2go/corespring/uml.ucls:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
18 |
19 |
20 |
21 |
22 |
24 |
25 |
27 |
28 |
29 |
30 |
31 |
33 |
34 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/ppts/DIP+IoC+DI.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/DIP+IoC+DI.pdf
--------------------------------------------------------------------------------
/ppts/代理模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/代理模式.pdf
--------------------------------------------------------------------------------
/ppts/单例.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/单例.pdf
--------------------------------------------------------------------------------
/ppts/命令模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/命令模式.pdf
--------------------------------------------------------------------------------
/ppts/工厂方法.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/工厂方法.pdf
--------------------------------------------------------------------------------
/ppts/抽象工厂.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/抽象工厂.pdf
--------------------------------------------------------------------------------
/ppts/构建者.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/构建者.pdf
--------------------------------------------------------------------------------
/ppts/桥接器.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/桥接器.pdf
--------------------------------------------------------------------------------
/ppts/模板方法模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/模板方法模式.pdf
--------------------------------------------------------------------------------
/ppts/流畅接口.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/流畅接口.pdf
--------------------------------------------------------------------------------
/ppts/策略模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/策略模式.pdf
--------------------------------------------------------------------------------
/ppts/简单工厂.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/简单工厂.pdf
--------------------------------------------------------------------------------
/ppts/组合模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/组合模式.pdf
--------------------------------------------------------------------------------
/ppts/职责链模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/职责链模式.pdf
--------------------------------------------------------------------------------
/ppts/装饰模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/装饰模式.pdf
--------------------------------------------------------------------------------
/ppts/观察者模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/观察者模式.pdf
--------------------------------------------------------------------------------
/ppts/解释器模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/解释器模式.pdf
--------------------------------------------------------------------------------
/ppts/迭代器模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/迭代器模式.pdf
--------------------------------------------------------------------------------
/ppts/适配器.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/适配器.pdf
--------------------------------------------------------------------------------
/ppts/门面模式.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring2go/core-spring-patterns/6df03a4bde6b0a425e2fc5aa7397264ec135292a/ppts/门面模式.pdf
--------------------------------------------------------------------------------