This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv 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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Composite design pattern" Watch "Composite design pattern" New topic

Composite design pattern

meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

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

Joined: Apr 06, 2010
Posts: 4541

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.
It is sorta covered in the JavaRanch Style Guide.
subject: Composite design pattern
It's not a secret anymore!