コード例 #1
0
        static void Main(string[] args)
        {
            Composite root = new Composite("root");

            root.AddChild(new Leaf("Leaf 1-A"));

            Composite composite = new Composite("Composite 1-B");
            composite.AddChild(new Leaf("Leaf 2-A"));
            composite.AddChild(new Leaf("Leaf 2-B"));

            root.AddChild(composite);
            root.AddChild(new Leaf("Leaf 1-C"));

            root.doOperation();
            Console.Read();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Dipen411/Patterns
        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.Read();
        }