装饰器模式
This commit is contained in:
@@ -11,11 +11,11 @@ package top.fjy8018.designpattern.pattern.structural.decorator.before;
|
||||
* @date 2018-09-27 16:56
|
||||
*/
|
||||
public class Battercake {
|
||||
protected String getDesc() {
|
||||
public String getDesc() {
|
||||
return "煎饼";
|
||||
}
|
||||
|
||||
protected int cost() {
|
||||
public int cost() {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ package top.fjy8018.designpattern.pattern.structural.decorator.before;
|
||||
*/
|
||||
public class BattercakeWithEgg extends Battercake {
|
||||
@Override
|
||||
protected String getDesc() {
|
||||
public String getDesc() {
|
||||
return super.getDesc() + " 加一个鸡蛋";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int cost() {
|
||||
public int cost() {
|
||||
return super.cost() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ package top.fjy8018.designpattern.pattern.structural.decorator.before;
|
||||
*/
|
||||
public class BattercakeWithEggSausage extends BattercakeWithEgg {
|
||||
@Override
|
||||
protected String getDesc() {
|
||||
public String getDesc() {
|
||||
return super.getDesc() + " 加一根香肠";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int cost() {
|
||||
public int cost() {
|
||||
return super.cost() + 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import top.fjy8018.designpattern.pattern.structural.decorator.after.ABattercake;
|
||||
import top.fjy8018.designpattern.pattern.structural.decorator.after.AbstractBattercake;
|
||||
import top.fjy8018.designpattern.pattern.structural.decorator.after.EggBattercake;
|
||||
import top.fjy8018.designpattern.pattern.structural.decorator.after.SausageBattercake;
|
||||
import top.fjy8018.designpattern.pattern.structural.decorator.before.Battercake;
|
||||
import top.fjy8018.designpattern.pattern.structural.decorator.before.BattercakeWithEgg;
|
||||
import top.fjy8018.designpattern.pattern.structural.decorator.before.BattercakeWithEggSausage;
|
||||
|
||||
@Slf4j
|
||||
class BattercakeTest {
|
||||
|
||||
Reference in New Issue
Block a user