• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Composite pattern - doubts/issues

 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
composite1.png
[Thumbnail for composite1.png]
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ideas? suggestions? criticisms?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic