Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Composite Pattern. Owners (No Twins, Expos) Managers (No Twins, Expos) Congress (No Twins, Expos) Media (No Twins, Expos) Radio (No Twins, Expos)

Similar presentations


Presentation on theme: "The Composite Pattern. Owners (No Twins, Expos) Managers (No Twins, Expos) Congress (No Twins, Expos) Media (No Twins, Expos) Radio (No Twins, Expos)"— Presentation transcript:

1 The Composite Pattern

2 Owners (No Twins, Expos) Managers (No Twins, Expos) Congress (No Twins, Expos) Media (No Twins, Expos) Radio (No Twins, Expos) Television (No Twins, Expos) Players (No Twins, Expos) Commissioner (No Twins, Expos)

3 Fireworks (Show) Flare (Show) Star (Show) Display (Show) FireworksGuy (Show)

4 Structural Object Pattern

5 Structural Patterns Concerned with how classes and objects are combined to create larger structures. Concerned with how classes and objects are combined to create larger structures.

6 Structural Object Patterns Are concerned with composing objects to establish new functionality. Are concerned with composing objects to establish new functionality.

7 Composite Pattern  Facilitates the composition of objects into tree structures that represent part-whole hierarchies.  These hierarchies consist of both primitive and composite objects.

8

9 Observations The Component (Graphic) is an abstract class that declares the interface for the objects in the pattern. As the interface, it declares methods (such as Draw) that are specific to the graphical objects. The Component (Graphic) is an abstract class that declares the interface for the objects in the pattern. As the interface, it declares methods (such as Draw) that are specific to the graphical objects. Line, Rectangle, and Text are so-called Leafs, which are subclasses that implement Draw to draw lines, rectangles, and text, respectively. Line, Rectangle, and Text are so-called Leafs, which are subclasses that implement Draw to draw lines, rectangles, and text, respectively.

10 Observations (Continued) The Picture class represents a number of graphics objects. It can call Draw on its children and also uses children to compose pictures using primitive objects. The Picture class represents a number of graphics objects. It can call Draw on its children and also uses children to compose pictures using primitive objects.

11 Concluding Considerations The Composite Pattern is used to represent part- whole object hierarchies. The Composite Pattern is used to represent part- whole object hierarchies. Clients interact with objects through the component class. Clients interact with objects through the component class. It enables clients to to ignore the specifics of which leaf or composite class they use. It enables clients to to ignore the specifics of which leaf or composite class they use. Can be used recursively, so that Display can show both flares and stars. Can be used recursively, so that Display can show both flares and stars. New components can easily be added to a design. New components can easily be added to a design.


Download ppt "The Composite Pattern. Owners (No Twins, Expos) Managers (No Twins, Expos) Congress (No Twins, Expos) Media (No Twins, Expos) Radio (No Twins, Expos)"

Similar presentations


Ads by Google