This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum 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
Register / Login


JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Reply Bookmark "Composite design pattern" Watch "Composite design pattern" New topic
Author

Composite design pattern

meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 226

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




OCAJP
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3860
    
    1

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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Composite design pattern
 
Similar Threads
GOF Question (Composite vs Flyweight)
(Visitor) two different collections
Problem in passing ArrayList
Dynamic hirarchical Menu by object and array list
Head First Design Patterns Composite Iterator