Beispiel #1
0
        static void CompositeInvoke()
        {
            // 生成树根,并为其增加两个叶子节点
            Composite.Composite root = new Composite.Composite("Root");
            root.Add(new Leaf("Leaf A in Root"));
            root.Add(new Leaf("Leaf B in Root"));

            // 为根增加两个枝节点
            Composite.Composite branchX = new Composite.Composite("Branch X in Root");
            Composite.Composite branchY = new Composite.Composite("Branch Y in Root");
            root.Add(branchX);
            root.Add(branchY);

            // 为BranchX增加页节点
            branchX.Add(new Leaf("Leaf A in Branch X"));

            // 为BranchX增加枝节点
            Composite.Composite branchZ = new Composite.Composite("Branch Z in Branch X");
            branchX.Add(branchZ);

            // 为BranchY增加叶节点
            branchY.Add(new Leaf("Leaf in Branch Y"));

            // 为BranchZ增加叶节点
            branchZ.Add(new Leaf("Leaf in Branch Z"));

            // 显示树
            root.Display(1);
        }
Beispiel #2
0
        public void CompositeTest()
        {
            // This way the client code can support the simple leaf components...
            var leaf = new Leaf();

            Client.ClientCode(leaf).Should().Be(StructuralText.Leaf);

            // ...as well as the complex composites.
            var tree    = new Composite.Composite();
            var branch1 = new Composite.Composite();

            branch1.Add(new Leaf());
            branch1.Add(new Leaf());
            var branch2 = new Composite.Composite();

            branch2.Add(new Leaf());
            tree.Add(branch1);
            tree.Add(branch2);
            Client.ClientCode(tree).Should().Be(StructuralText.CompositeResultA);
            Client.ClientCode2(tree, leaf).Should().Be(StructuralText.CompositeResultB);
        }
Beispiel #3
0
        private static void Main()
        {
            // ある意味これだけでFacadeとして体を成しているので
            // わざわざダミーのモジュールなどを作るまでもない。
            var root = new Composite.Composite("");

            root.Add(new Leaf("boot"));
            root.Add(new Composite.Composite("bin")).Add(new Leaf("ls"));
            var usr = root.Add(new Composite.Composite("usr"));

            usr.Add(new Composite.Composite("local"));
            usr.Add(new Composite.Composite("bin")).Add(new Leaf("perl"));
            usr.Add(new Composite.Composite("share")).Add(new Leaf("redmine"));
            usr.Add(new Composite.Composite("src"));
            root.Add(new Leaf("sbin"));
            root.Add(new Leaf("swap"));
            foreach (var p in root.GetDump())
            {
                Console.WriteLine(p);
            }
            Console.ReadKey();
        }