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