This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Composite pattern - doubts/issues Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Reply Bookmark "Composite pattern - doubts/issues" Watch "Composite pattern - doubts/issues" New topic
Author

Composite pattern - doubts/issues

Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 919
    
    2

I am trying to implement a Composite pattern as shown in the image below...

NOTE: Summary will have either handle1() or handle2()

1) Can I implement as shown in the figure - or should I have a base class like shown in the GoF composite structure?

2) For the summary part, I also have to implement a requirement where summary might have to be grouped by category. or user may choose to see just the overall summary.
In this case, I can have a list of child summaries. For overall sum, I can just loop through the I have 3 approaches:

A) loop through child summaries and call handle2()
In this case, each child summary will loop through the entire list and select only that satisfies its group - this will waste lot of time...

B) loop through items - do a condition check on child summaries and cal appropriate child summary's handle1()

C) Instead of the above way, I am thinking I should chain my child summaries - Chain of Resp. and handle will be passed on a need basis...
but in this case, I will need to loop through child summaries for totals - so, I end up maintaining both a List of child summaries and also the chain object in each summary - this approach saves time but uses up more memory...

is "C)" more complicated? can I combine patterns like this - composite & chain of resp?


[Thumbnail for composite1.png]


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 919
    
    2

ideas? suggestions? criticisms?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Composite pattern - doubts/issues
 
Similar Threads
Design Patterns...
Design Pattern for Chain of rules
Removing entries from a collection
Is my class thread safe? Help!
loop through arraylist of arrays