public static void Run() { Console.WriteLine("This real-world code demonstrates the Composite pattern used in building a graphical tree structure made up of primitive nodes (lines, circles, etc) and composite nodes (groups of drawing elements that make up more complex elements)."); CompositeElement root = new CompositeElement("Picture"); root.Add(new PrimitiveElement("Red Line")); root.Add(new PrimitiveElement("Blue Circle")); root.Add(new PrimitiveElement("Green Box")); CompositeElement comp = new CompositeElement("Two Circles"); comp.Add(new PrimitiveElement("Black Circle")); comp.Add(new PrimitiveElement("White Circle")); root.Add(comp); PrimitiveElement pe = new PrimitiveElement("Yellow Line"); root.Add(pe); root.Remove(pe); root.Display(1); /* * -+ Picture * --- Red Line * --- Blue Circle * --- Green Box * ---+ Two Circles * ----- Black Circle * ----- White Circle */ }
static void Main(string[] args) { // 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 = new PrimitiveElement("Yellow Line"); root.Add(pe); root.Remove(pe); // Recursively display nodes root.Display(1); Console.ReadKey(); }
/// <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 =new PrimitiveElement("Yellow Line"); root.Add(pe); root.Remove(pe); // Recursively display nodes root.Display(1); // Wait for user Console.ReadKey(); }
public static void Main() { // Create a tree structure var 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 var 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 var pe = new PrimitiveElement("Yellow Line"); root.Add(pe); root.Remove(pe); // Recursively display nodes root.Display(1); }
/// <summary> /// The test second composite. /// </summary> /// <exception cref="NotImplementedException"> /// </exception> private static void TestSecondComposite() { // 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 pelt = new PrimitiveElement("Yellow Line"); root.Add(pelt); root.Remove(pelt); // Recursively display nodes root.Display(1); // Wait for user Console.ReadKey(); }
static void Main(string[] args) { // Criar uma estrutura de árvore CompositeElement root = new CompositeElement("Picture"); root.Add(new PrimitiveElement("Red Line")); root.Add(new PrimitiveElement("Blue Circle")); root.Add(new PrimitiveElement("Green Box")); // Criar um ramo CompositeElement comp = new CompositeElement("Two Circles"); comp.Add(new PrimitiveElement("Black Circle")); comp.Add(new PrimitiveElement("White Circle")); root.Add(comp); // Adicionar e remover um PrimitiveElement PrimitiveElement pe = new PrimitiveElement("Yellow Line"); root.Add(pe); root.Remove(pe); // Recursivamente exibir nós root.Display(1); Console.ReadKey(); }
public static void Main() { var root = new CompositeElement { Name = "Picture" }; root.Add(new PrimitiveElement { Name = "Red Line" }); root.Add(new PrimitiveElement { Name = "Blue Circle" }); root.Add(new PrimitiveElement { Name = "Green Box" }); var childNode = new CompositeElement { Name = "Two Circles" }; childNode.Add(new PrimitiveElement { Name = "Black Circle" }); childNode.Add(new PrimitiveElement { Name = "White Circle" }); root.Add(childNode); root.Display(); }
static void Main(string[] args) { // Create a tree structure CompositeElement root = new CompositeElement("McDonald's A.K.A. Macca's"); root.Add(new PrimitiveElement("Big Mac")); root.Add(new PrimitiveElement("Quarter Pounder with Cheese")); root.Add(new PrimitiveElement("McNifica")); // Create a branch CompositeElement comp = new CompositeElement("Burger King A.K.A. Hungry Jacks"); comp.Add(new PrimitiveElement("Whopper")); comp.Add(new PrimitiveElement("Big King")); comp.Add(new PrimitiveElement("Crispy King")); root.Add(comp); // Create a branch CompositeElement carls = new CompositeElement("Carl's Jr."); carls.Add(new PrimitiveElement("Famous Star")); carls.Add(new PrimitiveElement("Western Bacon")); carls.Add(new PrimitiveElement("Diablo")); root.Add(carls); // Create a branch CompositeElement innout = new CompositeElement("In 'n' Out"); innout.Add(new PrimitiveElement("Double-Double")); innout.Add(new PrimitiveElement("Cheeseburger")); innout.Add(new PrimitiveElement("Hamburger")); root.Add(innout); // Add and remove a PrimitiveElement PrimitiveElement pe = new PrimitiveElement("Yellow Line"); root.Add(pe); root.Remove(pe); // Recursively display nodes root.Display(1); // Wait for user Console.ReadKey(); }
static void Main(string[] args) { var root = new CompositeElement("Picture"); root.Add(new PrimitiveElement("Red line")); root.Add(new PrimitiveElement("Green box")); var comp = new CompositeElement("Circles"); comp.Add(new PrimitiveElement("Black circle")); comp.Add(new PrimitiveElement("Red circle")); root.Add(comp); root.Display(); }
static void Main(string[] args) { // Create a tree structure //Elemento raiz CompositeElement root = new CompositeElement("Picture"); //Nivel 1 root.Add(new PrimitiveElement("Red Line")); root.Add(new PrimitiveElement("Blue Circle")); root.Add(new PrimitiveElement("Green Box")); root.Add(new PrimitiveElement("Purple Triangle")); // Create a branch //Nivel 2 CompositeElement comp = new CompositeElement("Two Circles"); comp.Add(new PrimitiveElement("Black Circle")); comp.Add(new PrimitiveElement("White Circle")); root.Add(comp); //level 3 CompositeElement lvl3 = new CompositeElement("Two Triangle"); lvl3.Add(new PrimitiveElement("Coral Triangle")); lvl3.Add(new PrimitiveElement("Cyan Triangle")); comp.Add(lvl3); // Add and remove a PrimitiveElement PrimitiveElement pe = new PrimitiveElement("Yellow Line"); root.Add(pe); root.Remove(pe); // Recursively display nodes root.Display(1); // Wait for user Console.ReadKey(); }
public static void Run() { Console.WriteLine("\n Composite Real World Practice"); CompositeElement root = new CompositeElement("Picture"); root.Add(new PrimitiveElement("Red Line")); root.Add(new PrimitiveElement("Blue Circle")); root.Add(new PrimitiveElement("Green Box")); CompositeElement comp = new CompositeElement("Two Circles"); comp.Add(new PrimitiveElement("Black Circle")); comp.Add(new PrimitiveElement("White Circle")); root.Add(comp); PrimitiveElement pe = new PrimitiveElement("Yellow Line"); root.Add(pe); root.Remove(pe); root.Display(1); }
static void Main(string[] args) { CompositeElement root = new CompositeElement("Picture"); root.Add(new LeafElement("Red Line")); root.Add(new LeafElement("Blue Circle")); root.Add(new LeafElement("Green Box")); CompositeElement comp = new CompositeElement("Two Circles"); comp.Add(new LeafElement("Black Circle")); comp.Add(new LeafElement("White Circle")); root.Add(comp); LeafElement pe = new LeafElement("Yellow Line"); root.Add(pe); root.Remove(pe); root.Display(1); }
/// <summary> /// Compose objects into tree structures to represent part-whole hierarchies. /// Composite lets clients treat individual objects and compositions of objects uniformly. /// </summary> static void Main() { CompositeElement root = new CompositeElement("Picture"); root.Add(new PrimitiveElement("Red Line")); root.Add(new PrimitiveElement("Blue Circle")); root.Add(new PrimitiveElement("Green Box")); CompositeElement comp = new CompositeElement("Two Circles"); comp.Add(new PrimitiveElement("Black Circle")); comp.Add(new PrimitiveElement("White Circle")); root.Add(comp); PrimitiveElement pe = new PrimitiveElement("Yellow Line"); root.Add(pe); root.Remove(pe); root.Display(1); Console.ReadKey(); }
static void Main(string[] args) { // Create a tree structure CompositeElemnt root = new CompositeElement("Video"); root.Add(new PrimitiveElement("Duration")); CompositeElement fps = new Compositeelement("Frames Per Second"); root.Add(fps); CompositeElement photo = new CompositeElement("Photo"); fps.Add(photo); CompositeElement picture = new CompositeElement("Picture"); picture.Add(new PrimitiveElement("Color Blue")); picture.Add(new PrimitiveElement("Color Red")); picture.Add(new PrimitiveElement("Color Yellow")); photo.Add(picture); CompositeElement line = new CompositeElement("Line"); picture.Add(new PrimitiveElement("Color Blue")); picture.Add(new PrimitiveElement("Color Red")); picture.Add(new PrimitiveElement("Color Yellow")); picture.Add(line); CompositeElement circle = new CompositeElement("Circle"); picture.Add(new PrimitiveElement("Color Blue")); picture.Add(new PrimitiveElement("Color Red")); picture.Add(new PrimitiveElement("Color Yellow")); picture.Add(circle); CompositeElement square = new CompositeElement("square"); picture.Add(new PrimitiveElement("Color Blue")); picture.Add(new PrimitiveElement("Color Red")); picture.Add(new PrimitiveElement("Color Yellow")); picture.Add(square); // 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 = new PrimitiveElement("Yellow Line"); pe.Add(new CompositeElement("Blue Point")); root.Add(pe); root.Remove(pe); // Recursively display nodes root.Display(1); // Wait for user Console.ReadKey(); }