The 'Leaf' class
Inheritance: Component
Ejemplo n.º 1
0
        /// <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();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Container tree = new Container("root");
            Container a1= new Container("a1");
            INode b1 = new Leaf("b1");
            INode a2 = new Leaf("a2");
            INode a3 = new Leaf("a3");

            tree.Add(a1);
            tree.Add(b1);
            a1.Add(a2);
            a1.Add(a3);

            Console.WriteLine(tree.Print());

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void Main()
        {           
            Composite system = new Composite("System");
            system.Add(new Leaf("System.Element 1"));
            system.Add(new Leaf("System.Element 2"));

            Composite subsystem1 = new Composite("System.Subsystem1");
            subsystem1.Add(new Leaf("System.Subsystem1.Element1"));
            subsystem1.Add(new Leaf("System.Subsystem1.Element2"));

            system.Add(subsystem1);
            system.Add(new Leaf("System.Element 3"));

            Leaf leaf = new Leaf("System.Element 4");
            system.Add(leaf);
            system.Remove(leaf);

            system.Display(1);
            
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void Main()
        {
            var root = new Composite("root");
            root.AddChild(new Leaf("Leaf 1"));
            root.AddChild(new Leaf("Leaf 2"));

            var comp = new Composite("Composite C");
            comp.AddChild(new Leaf("Leaf C.1"));
            comp.AddChild(new Leaf("Leaf C.2"));

            root.AddChild(comp);
            root.AddChild(new Leaf("Leaf 3"));

            var leaf = new Leaf("Leaf 4");
            root.AddChild(leaf);
            root.RemoveChild(leaf);

            root.Display(1);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            ConcreteCompany companyRoot = new ConcreteCompany("北京總公司");

            companyRoot.Add(new HRDepartment("總公司人力資源部"));
            companyRoot.Add(new FinanceDepartment("總公司財務部"));

            ConcreteCompany companyA = new ConcreteCompany("上海華東分公司");

            companyA.Add(new HRDepartment("華東分公司人力資源部"));
            companyA.Add(new FinanceDepartment("華東分公司財務部"));
            companyRoot.Add(companyA);

            ConcreteCompany companyB = new ConcreteCompany("南京辦事處");

            companyB.Add(new HRDepartment("南京辦事處人力資源部"));
            companyB.Add(new FinanceDepartment("南京辦事處財務部"));
            companyA.Add(companyB);

            ConcreteCompany companyC = new ConcreteCompany("杭州辦事處");

            companyC.Add(new HRDepartment("杭州辦事處人力資源部"));
            companyC.Add(new FinanceDepartment("杭州辦事處財務部"));
            companyA.Add(companyC);

            Console.WriteLine("組織結構圖");
            companyRoot.Display(1);

            Console.WriteLine("\n職責");
            companyRoot.LineOfDuty();

            Console.WriteLine("\n");

            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);

            Composite comp2 = new Composite("Composite XY");

            comp2.Add(new Leaf("Leaf XYA"));
            comp2.Add(new Leaf("Leaf XYB"));

            comp.Add(comp2);

            root.Add(new Leaf("Leaf C"));

            Leaf leafD = new Leaf("Leaf D");

            root.Add(leafD);
            root.Remove(leafD);

            root.Display(1);

            Console.ReadLine();
        }