04 - Composite realworld.doc - Composite pattern Real World example using System using System.Collections.Generic namespace

04 - Composite realworld.doc - Composite pattern Real World...

This preview shows page 1 - 3 out of 4 pages.

// Composite pattern -- Real World example using System; using System.Collections.Generic; namespace DoFactory.GangOfFour.Composite.RealWorld { /// <summary> /// MainApp startup class for Real-World /// Composite Design Pattern. /// </summary> class MainApp { /// <summary> /// Entry point into console application. /// </summary> static void Main() { // Create a tree structure CompositeElement root = new CompositeElement ( "Picture" ); root.Add( new PrimitiveElement ( "Red Line" )); root.Add( new PrimitiveElement ( "Blue Circle" )); root.Add( new PrimitiveElement ( "Green Box" )); // Create a branch CompositeElement comp = new CompositeElement ( "Two Circles" ); comp.Add( new PrimitiveElement ( "Black Circle" )); comp.Add( new PrimitiveElement ( "White Circle" )); root.Add(comp); // Add and remove a PrimitiveElement PrimitiveElement pe =
Image of page 1

Subscribe to view the full document.

new PrimitiveElement ( "Yellow Line" ); root.Add(pe); root.Remove(pe); // Recursively display nodes root.Display(1); // Wait for user Console .ReadKey(); } } /// <summary> /// The 'Component' Treenode /// </summary> abstract class DrawingElement { protected string _name; // Constructor public DrawingElement( string name) { this ._name = name;
Image of page 2
Image of page 3
  • Fall '19
  • Martha

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes