Beispiel #1
0
        static void Main(string[] args)
        {
            Composite c  = new Composite("老大");
            Composite c1 = new Composite("老二");
            Composite c2 = new Composite("老三");

            Leaf l1 = new Leaf("小弟1");
            Leaf l2 = new Leaf("小弟2");
            Leaf l3 = new Leaf("小弟3");
            Leaf l4 = new Leaf("小弟4");
            Leaf l5 = new Leaf("小弟5");
            Leaf l6 = new Leaf("小弟6");
            Leaf l7 = new Leaf("小弟7");

            c.Add(l1);
            c.Add(l2);
            c1.Add(l3);
            c1.Add(l4);
            c1.Add(l5);
            c1.Add(l6);
            c2.Add(l7);
            c.Add(c1);
            c.Add(c2);

            c.DisPlay(1);

            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Composite root=new Composite("root");
             root.Add(new Leaf("Leag A"));
             root.Add(new Leaf("Leaf B"));

            Composite comp = new Composite("Composite X");
            comp.Add(new Leaf("Composite XA"));
            comp.Add(new Leaf("Composite XB"));

            root.Add(comp);
            root.Add(new Leaf("C"));
            root.DisPlay(1);

            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Composite root = new Composite("root");

            root.Add(new Leaf("Leag A"));
            root.Add(new Leaf("Leaf B"));

            Composite comp = new Composite("Composite X");

            comp.Add(new Leaf("Composite XA"));
            comp.Add(new Leaf("Composite XB"));

            root.Add(comp);
            root.Add(new Leaf("C"));
            root.DisPlay(1);

            Console.ReadKey();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            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 leaf = new Leaf("Leaf D");

            root.Add(leaf);
            root.Remove(leaf);

            root.Display(1);

            ConcreteCompany rootCompany = new ConcreteCompany("南京总公司");

            rootCompany.Add(new HRDepartment("总公司人力资源部"));


            Console.Read();
        }
Beispiel #5
0
        public static void StartExample()
        {
            /*
             * 组合模式原型
             *
             */
            //定义一个根节点
            Composite root = new Composite()
            {
                Name = "root根节点"
            };

            root.Add(new Leaf()
            {
                Name = "root 叶子节点A"
            });
            root.Add(new Leaf()
            {
                Name = "root 叶子节点B"
            });

            //定义一个枝结点
            Composite composite = new Composite()
            {
                Name = "root枝节点A"
            };

            composite.Add(new Leaf()
            {
                Name = "composite 叶子节点A"
            });
            composite.Add(new Leaf()
            {
                Name = "composite 叶子节点B"
            });

            //定义一个枝结点
            Composite composite1 = new Composite()
            {
                Name = "root枝节点B"
            };

            composite1.Add(new Leaf()
            {
                Name = "composite1 叶子节点A"
            });
            composite1.Add(new Leaf()
            {
                Name = "composite1 叶子节点B"
            });


            //为根节点添加枝结点
            root.Add(composite);
            root.Add(composite1);

            //为根节点添加叶子节点
            root.Add(new Leaf()
            {
                Name = "root 叶子节点C"
            });
            root.Add(new Leaf()
            {
                Name = "root 叶子节点D"
            });

            //显示树形结构
            root.DisPlay(1);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Composite root = new Composite("root");
            root.Add(new Leaf("A"));
            root.Add(new Leaf("B"));
            Composite composit1 = new Composite("composite1");
            composit1.Add(new Leaf("A1"));
            composit1.Add(new Leaf("B1"));
            root.Add(composit1);
            root.Add(new Leaf("C"));

            root.Display(1);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            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 leaf = new Leaf("Leaf D");
            root.Add(leaf);
            root.Remove(leaf);

            root.Display(1);

            Console.Read();
        }