Composite Pattern

1,061 views

Published on

Composite Pattern 2007 Nov

Published in: Economy & Finance, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,061
On SlideShare
0
From Embeds
0
Number of Embeds
30
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Composite Pattern

  1. 1. Composite Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
  2. 3. Replace Implicit Tree With Composite <ul><li>Identify an implicit leaf. </li></ul><ul><li>Replace every occurrence of the implicit leaf with an instance of the leaf node. </li></ul><ul><li>Repeat steps 1 and 2 for any additional parts of the implicit tree that represent an implicit leaf. Make sure all leaf nodes share a common interface. </li></ul>
  3. 4. Replace Implicit Tree With Composite <ul><li>Identify an implicit parent. </li></ul><ul><li>Replace every occurrence of the implicit parent with an instance of the parent node. </li></ul><ul><li>Repeat steps 4 and 5 for any additional parts of the implicit tree that represent an implicit leaf. Make sure all leaf nodes share a common interface. </li></ul>
  4. 6. Benefits & Liabilities <ul><li>+ Encapsulates repetitive instructions like formatting, adding, or removing nodes. </li></ul><ul><li>+ Provides a generalised way to handle a proliferation of similar logic. </li></ul><ul><li>+ Simplifies construction responsibilities. </li></ul><ul><li>- Complicates a design when it’s simpler to construct implicit trees. </li></ul>
  5. 7. Implementation Issues <ul><li>Explicit parent references </li></ul><ul><li>Sharing components </li></ul><ul><li>Maximising the Component interface </li></ul><ul><li>Declaring the child management operations </li></ul><ul><li>Should Component implement a list of Components? </li></ul><ul><li>Child ordering </li></ul><ul><li>Caching to improve performance </li></ul><ul><li>Who should delete components? </li></ul><ul><li>What’s the best structure for storing components </li></ul>
  6. 8. In Relation to other Patterns <ul><li>Flyweight </li></ul><ul><li>Visitor </li></ul><ul><li>MVC </li></ul><ul><li>Interpreter </li></ul><ul><li>Command (Macro Command) </li></ul>

×