decorator运行时为对象添加功能
decorator 装饰者
public interface IHelloPrinter
{
    void PrintHello();
}

public interface IHelloPrinterDecorator : IHelloPrinter
{
    void PrintGoodbye();
}

public abstract class AbstractHelloPrinterDecorator:IHelloPrinterDecorator
{
    IHelloPrinter helloPrinter;
    public AbstractHelloPrinterDecorator(IHelloPrinter helloPrinter)
 {
        this.helloPrinter = helloPrinter;
 }
    public void PrintHello()
    {
        helloPrinter.PrintHello();

    }

   public abstract void PrintGoodbye();
}

public class EnglishHelloPrinterDecorator : AbstractHelloPrinterDecorator
{
    EnglishHelloPrinterDecorator(IHelloPrinter helloPrinter)
        : base(helloPrinter)
    {

    }

    public override void PrintGoodbye()
    {
        throw new Exception("The method or operation is not implemented.");
    }
}

public class GermanHelloPrinterDecorator : AbstractHelloPrinterDecorator
{
    GermanHelloPrinterDecorator(IHelloPrinter helloPrinter)
        : base(helloPrinter)
    {

    }

    public override void PrintGoodbye()
    {
        throw new Exception("The method or operation is not implemented.");
    }
}

相关文章:

  • 2022-01-20
  • 2021-09-06
  • 2021-05-02
  • 2021-05-16
  • 2021-11-16
  • 2021-06-27
猜你喜欢
  • 2021-05-19
  • 2021-07-03
  • 2021-10-17
  • 2021-11-15
  • 2022-12-23
相关资源
相似解决方案