/// <summary> /// Entry point into console application. /// </summary> static void Main() { // Create a tree structure Composite root = new Composite("root"); root.Add(new Leaf("Leaf A")); root.Add(new Leaf("Leaf B")); Composite comp = new Composite("Composite X"); comp.Add(new Leaf("Leaf XA")); comp.Add(new Leaf("Leaf XB")); root.Add(comp); root.Add(new Leaf("Leaf C")); // Add and remove a leaf Leaf leaf = new Leaf("Leaf D"); root.Add(leaf); root.Remove(leaf); // Recursively display tree root.Display(1); // Wait for user Console.ReadKey(); }
private static void Main(string[] args) { #region 结构实现 // Create a tree structure Structural.Composite root = new Structural.Composite("root"); root.Add(new Leaf("Leaf A")); root.Add(new Leaf("Leaf B")); Structural.Composite comp = new Structural.Composite("Composite X"); comp.Add(new Leaf("Leaf XA")); comp.Add(new Leaf("Leaf XB")); root.Add(comp); root.Add(new Leaf("Leaf C")); // Add and remove a leaf Leaf leaf = new Leaf("Leaf D"); root.Add(leaf); root.Remove(leaf); // Recursively display tree root.Display(1); #endregion Console.WriteLine("******************************"); #region 实践应用 Graphics graphics = new Graphics("全部图形"); Circle circle = new Circle("圆形", 5); graphics.Add(circle); Rectangle rectangle = new Rectangle("矩形", 4, 5); graphics.Add(rectangle); Triangle triangle = new Triangle("三角形", 3, 4, 5); graphics.Add(triangle); graphics.Display(); #endregion Console.ReadKey(); }