static void Main(string[] args) { //何时使用:在不想增加很多子类的情况下扩展类。 RedShapeDecorator decorator = new RedShapeDecorator(new Rectangle()); decorator.Draw(); Console.ReadLine(); }
static void Main(string[] args) { IShape circle = new Circle(); Console.WriteLine("Circle with normal border"); circle.Draw(); IShape decoratorCircle = new RedShapeDecorator(new Circle()); Console.WriteLine("\nCircle of red border"); decoratorCircle.Draw(); IShape decoratorRectangle = new RedShapeDecorator(new Rectangle()); decoratorRectangle = new GreenShapeDecorator(decoratorRectangle); Console.WriteLine("\nRectangle of red border and green background"); decoratorRectangle.Draw(); Console.ReadLine(); }