Inheritance: Component
        static void Main()
        {
            var root = new Composite()
                .AddChild(
                    new Composite()
                        .AddChild(new IntNode(1))
                        .AddChild(new IntNode(2))
                        .AddChild(new IntNode(7))
                        .AddChild(new IntNode(3))
                        .AddChild(new IntNode(9))
                );
            Console.WriteLine(root.GetValue);

            var newroot = root.AddChild(
                new Composite()
                    .AddChild(new IntNode(4))
                    .AddChild(
                        new Composite()
                            .AddChild(new IntNode(3))
                            .AddChild(new IntNode(8))
                            .AddChild(new IntNode(1))
                    )
            );
            Console.WriteLine(root.GetValue);
            Console.WriteLine(newroot.GetValue);

            Console.ReadLine();
        }
示例#2
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();
        }
示例#3
0
        static void Main(string[] args)
        {
            IVisitor v = new ImprimeArbolCompacto();

            Composite.Composite root = inicialize();

            root.ToString();
        }
示例#4
0
        public void TestIntGallega()
        {
            composite2 = new Directorio("apuñaló", x => QuitAccents(x.Replace("ñ", "nh")));
            composite3 = new Comprimido("apuñaló", x => QuitAccents(x.Replace("ñ", "nh")));
            hoja       = new Archivo("apuñaló", 5, x => QuitAccents(x.Replace("ñ", "nh")));
            e          = new EnlaceDirecto(composite2, x => QuitAccents(x.Replace("ñ", "nh")));

            Assert.AreEqual(composite2.ToString(), "apunhalo");
            Assert.AreEqual(composite3.ToString(), "apunhalo");
            Assert.AreEqual(hoja.ToString(), "apunhalo");
            Assert.AreEqual(e.ToString(), "apunhalo");
        }
示例#5
0
        public void TestCatalana()
        {
            composite2 = new Directorio("apuñaló", x => x.Replace("ñ", "ny"));
            composite3 = new Comprimido("apuñaló", x => x.Replace("ñ", "ny"));
            hoja       = new Archivo("apuñaló", 5, x => x.Replace("ñ", "ny"));
            e          = new EnlaceDirecto(composite2, x => x.Replace("ñ", "ny"));

            Assert.AreEqual(composite2.ToString(), "apunyaló");
            Assert.AreEqual(composite3.ToString(), "apunyaló");
            Assert.AreEqual(hoja.ToString(), "apunyaló");
            Assert.AreEqual(e.ToString(), "apunyaló");
        }
        public void startUp()
        {
            borrar    = new Archivo("hoja4", 5, x => x);
            composite = new Directorio("root", x => x);
            Composite.Composite composite2 = new Directorio("dir", x => x);
            Composite.Composite composite3 = new Comprimido("comp", x => x);


            composite3.addComponente(new Archivo("hoja1", 5, x => x));
            composite3.addComponente(new Archivo("hoja2", 5, x => x));

            composite2.addComponente(new Archivo("hoja3", 5, x => x));
            composite2.addComponente(composite3);

            EnlaceDirecto e = new EnlaceDirecto(composite2, x => x);

            composite.addComponente(borrar);
            composite.addComponente(composite2);
            composite.addComponente(e);
        }
示例#7
0
文件: Program.cs 项目: Alex-LG/DP
        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();
        }
        public void startUp()
        {
            Estrategia est = new InternacionalCatalan();

            borrar    = new Archivo("hoja4", 5, est);
            composite = new Directorio("root", est);
            Composite.Composite composite2 = new Directorio("dir", est);
            Composite.Composite composite3 = new Comprimido("comp", est);


            composite3.addComponente(new Archivo("hoja1", 5, est));
            composite3.addComponente(new Archivo("hoja2", 5, est));

            composite2.addComponente(new Archivo("hoja3", 5, est));
            composite2.addComponente(composite3);

            EnlaceDirecto e = new EnlaceDirecto(composite2, est);

            composite.addComponente(borrar);
            composite.addComponente(composite2);
            composite.addComponente(e);
        }
示例#9
0
 static void Main(string[] args)
 {
     Component components = new Composite("root");
     components.Add(new Leaf("FIRST"));
     Component second = new Composite("SECOND");
     Component second1 = new Composite("SECOND 1");
     Component second2 = new Composite("SECOND 2");
     second2.Add(new Leaf("SECOND 3"));
     second1.Add(second2);
     second.Add(second1);
     components.Add(second);
     components.Add(new Leaf("THIRD"));
     components.Add(second1);
     components.Add(second2);
     components.Display(0);
     Console.ReadKey();
 }
示例#10
0
 public override void Remove(Composite c)
 {
     Console.WriteLine("Can not remove from a leaf");
 }
示例#11
0
 public override void Add(Composite c)
 {
     Console.WriteLine("Can not add to a leaf");
 }
示例#12
0
 public override void Remove(Composite c)
 {
     children.Remove(c);
 }
示例#13
0
 public override void Add(Composite c)
 {
     children.Add(c);
 }
示例#14
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);
        }
示例#15
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();
        }