File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Composite pattern - doubts/issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Composite pattern - doubts/issues" Watch "Composite pattern - doubts/issues" New topic

Composite pattern - doubts/issues

Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1101

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]

Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1101

ideas? suggestions? criticisms?
I agree. Here's the link:
subject: Composite pattern - doubts/issues
It's not a secret anymore!