This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Composite design pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Composite design pattern" Watch "Composite design pattern" New topic
Author

Composite design pattern

meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

Hi,
i created this program from my understanding, do you think this is correct example of composite design pattern ?




My one regret in life is that I am not someone else.
- Woody Allen
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

No, because all that allows you to go is have a Composite containing a single Leaf. The idea behind the composite pattern is to allow you to build a hierarchy of grouped objects. So what you need is to implement it so that each Composite object can contain multiple Component objects (not just Leafs). That way you can put Composites inside Composites.
 
jQuery in Action, 2nd edition
 
subject: Composite design pattern
 
Similar Threads
Dynamic hirarchical Menu by object and array list
Problem in passing ArrayList
GOF Question (Composite vs Flyweight)
(Visitor) two different collections
Head First Design Patterns Composite Iterator