Example #1
0
        static void Main(string[] args)
        {
            // root composite
            var box = new Composite("Box", 0);


            // pen and pencil in composite pencil_case
            var pen         = new Leaf("pen", 5);
            var pencil      = new Leaf("pencil", 3);
            var Pencil_case = new Composite("Pencil case", 0);
            var Ball        = new Leaf("Ball", 200);

            Pencil_case.AddChild(pen);
            Pencil_case.AddChild(pencil);


            // add pencil composite as child to the root composite
            box.AddChild(Pencil_case);



            // add leaf component as child to the root composite
            box.AddChild(Ball);

            Console.WriteLine($"Total price of this box  is: {box.Caclulate()}");
        }
        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();
        }
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            // Create a simple tree structure
            Composite root = new Composite();

            root.AddChild(new Leaf());
            root.AddChild(new Leaf());
            Composite composite = new Composite();

            composite.AddChild(new Leaf());
            composite.AddChild(new Leaf());
            root.AddChild(composite);

            // perform operation on entire tree
            root.DoThis();
        }