File tree Expand file tree Collapse file tree
src/main/java/com/cpucode/pattern/decorator/batter/cake/v1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments