Skip to content

Commit fc97521

Browse files
committed
煎饼装饰
1 parent a635e74 commit fc97521

5 files changed

Lines changed: 96 additions & 3 deletions

File tree

pattern/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@
9898
- [x] [登录适配器](src/main/java/com/cpucode/pattern/adapter/login/adapter/v1/service/SigninForThirdServiceTest.java)
9999
- [x] [各登录适配器](src/main/java/com/cpucode/pattern/adapter/login/adapter/v2/PassportTest.java)
100100

101-
## [装饰器模式]()
102-
103-
- [] []()
101+
## [装饰器模式](src/main/java/com/cpucode/pattern/decorator)
104102

103+
- [x] [煎饼装饰](src/main/java/com/cpucode/pattern/decorator/batter/cake/v1/BatterCakeTest.java)
104+
- [x] [煎饼装饰v2](src/main/java/com/cpucode/pattern/decorator/batter/cake/v2/BattercakeTest.java)
105105

106106
----------------
107107

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.cpucode.pattern.decorator.batter.cake.v1;
2+
3+
/**
4+
* @author : cpucode
5+
* @date : 2021/7/10
6+
* @time : 23:26
7+
* @github : https://github.com/CPU-Code
8+
* @csdn : https://blog.csdn.net/qq_44226094
9+
*/
10+
public class BatterCake {
11+
protected String getMsg(){
12+
return "煎饼";
13+
}
14+
15+
public int getPrice(){
16+
return 5;
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.cpucode.pattern.decorator.batter.cake.v1;
2+
3+
/**
4+
* @author : cpucode
5+
* @date : 2021/7/10
6+
* @time : 23:30
7+
* @github : https://github.com/CPU-Code
8+
* @csdn : https://blog.csdn.net/qq_44226094
9+
*/
10+
public class BatterCakeTest {
11+
public static void main(String[] args) {
12+
BatterCake batterCake = new BatterCake();
13+
14+
System.out.println(batterCake.getMsg() + ", 总价格:" + batterCake.getPrice());
15+
16+
BatterCake batterCakeWithEgg = new BatterCakeWithEgg();
17+
System.out.println(batterCakeWithEgg.getMsg() +
18+
", 总价格:" +
19+
batterCakeWithEgg.getPrice());
20+
21+
BatterCake battercakeWithEggAndSausage = new BatterCakeWithEggAndSausage();
22+
System.out.println(battercakeWithEggAndSausage.getMsg() +
23+
", 总价格:" +
24+
battercakeWithEggAndSausage.getPrice());
25+
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.cpucode.pattern.decorator.batter.cake.v1;
2+
3+
/**
4+
* @author : cpucode
5+
* @date : 2021/7/10
6+
* @time : 23:28
7+
* @github : https://github.com/CPU-Code
8+
* @csdn : https://blog.csdn.net/qq_44226094
9+
*/
10+
public class BatterCakeWithEgg extends BatterCake{
11+
@Override
12+
protected String getMsg(){
13+
return super.getMsg() + "+1个鸡蛋";
14+
}
15+
16+
/**
17+
* 加一个鸡蛋加1块钱
18+
* @return
19+
*/
20+
@Override
21+
public int getPrice() {
22+
return super.getPrice() + 1;
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.cpucode.pattern.decorator.batter.cake.v1;
2+
3+
/**
4+
* @author : cpucode
5+
* @date : 2021/7/10
6+
* @time : 23:29
7+
* @github : https://github.com/CPU-Code
8+
* @csdn : https://blog.csdn.net/qq_44226094
9+
*/
10+
public class BatterCakeWithEggAndSausage extends BatterCakeWithEgg {
11+
@Override
12+
protected String getMsg() {
13+
return super.getMsg() + "+1根香肠";
14+
}
15+
16+
/**
17+
* 加一个香肠加2块钱
18+
* @return
19+
*/
20+
@Override
21+
public int getPrice() {
22+
return super.getPrice() + 2;
23+
}
24+
}

0 commit comments

Comments
 (0)