Beispiel #1
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();
    }
Beispiel #2
0
        static void Main()
        {
            Composite kingdom = new Composite("Kingdom");

            Composite animalia = new Composite("Animalia");
            animalia.Add(new Leaf("Around 1.4M species"));

            Composite phylluma = new Composite("Phyllum");
            phylluma.Add(new Leaf("Chordata"));
            phylluma.Add(new Leaf("annelida"));
            phylluma.Add(new Leaf("Others.."));

            Composite plantae = new Composite("Plantae");
            plantae.Add(new Leaf("Around 275000 species"));

            Composite phyllump = new Composite("Phyllum");
            phyllump.Add(new Leaf("Angiospermae"));
            phyllump.Add(new Leaf("Marcantiophyta"));
            phyllump.Add(new Leaf("Others.."));

            kingdom.Add(animalia);
            kingdom.Add(plantae);
            animalia.Add (phylluma);
            plantae.Add (phyllump);

            Leaf leaf = new Leaf("Leaf D");
            kingdom.Add(leaf);
            kingdom.Remove(leaf);

            kingdom.Display(1);

            Console.ReadKey();
        }