1. 程式人生 > 實用技巧 >ASP.NET Core 3 起架設在 Windows IIS 方式改變

ASP.NET Core 3 起架設在 Windows IIS 方式改變

裝飾器和繼承的區別

  • 繼承模式: 這種方式是靜態的, 一定是要寫一個新的子類, 對類層級進行拓展
  • 裝飾器模式(關聯機制): 動態的; 拿到一個物件就可以對其進行拓展, 不需要修改原有類的邏輯

類圖

package 裝飾器模式;

import jdk.nashorn.internal.ir.annotations.Ignore;

import static java.lang.annotation.ElementType.PARAMETER;

/**
 * @author 無法手執玫瑰
 * 2020/11/0023 21:13
 */
public class DecoratorPatter {
    public static void main(String[] args) {
        new RobotDecorator(new FirstRobot()).doMoreThing();
    }

}
interface Robot{
    void doSomething();
}

class FirstRobot implements Robot{

    @Override
    public void doSomething() {
        System.out.println("唱歌");
        System.out.println("對話");
    }
}

class RobotDecorator implements Robot{
    private Robot robot;

    public RobotDecorator(Robot robot) {
        this.robot = robot;
    }

    @Override
    public void doSomething() {
        robot.doSomething();
    }
    public void doMoreThing(){
        robot.doSomething();
        System.out.println("跳舞");
        System.out.println("拖地");
    }
}