/// <summary> /// 初始状况. /// </summary> private static void Test1() { // 使用抽象构件定义 ComponentUI component, componentSB; // 定义具体构件 component = new Window(); // 定义装饰后的构件 componentSB = new ScrollBarDecorator(component); // 显示. componentSB.Display(); }
public static void Main() { Console.WriteLine("Document : Text --> \n"); DocumentComponent documentComponentText = new BorderDecorator(new FontDecorator(new HeaderAndFooterDecorator(new TextView()))); documentComponentText.DisplayDocument(); Console.WriteLine("Total Size : " + documentComponentText.GetSize()); Console.WriteLine("Document : Graph --> \n"); DocumentComponent documentComponentGraph = new ScrollBarDecorator(new GraphView()); documentComponentGraph.DisplayDocument(); Console.WriteLine("Total Size : " + documentComponentGraph.GetSize()); }
/// <summary> /// 增加需求后的修改代码. /// </summary> private static void Test2() { //全部使用抽象构件定义 ComponentUI component, componentSB, componentBB; // 定义具体构件 component = new Window(); // 定义装饰后的构件 componentSB = new ScrollBarDecorator(component); //将装饰了一次之后的对象继续注入到另一个装饰类中,进行第二次装饰 componentBB = new BlackBorderDecorator(componentSB); // 显示. componentBB.Display(); }
static void Main(string[] args) { Component component = new Window(); Component componentSB = new ScrollBarDecorator(component); componentSB.Display(); Console.WriteLine(); Component componentBB = new BlackBorderDecorator(componentSB); componentBB.Display(); Console.ReadKey(); }