Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Is Composite pattern appropriate ?

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can the composite pattern be used to support the following budget structure (a tree):
My GUI will allow the input of amounts. Each amount can be broken down into sub-amounts. Basically, the value stored in a node will be the sum of the amounts of its immediate children.
I see a difficulty arising because the tree has two types of leafs: horizontal amounts and vertical amounts. The sum of the horizontal amounts and the sum of the vertical amounts will both be equal to the amount of their common parent.
Reports will have to be produced grouping the horizontal and the vertical amounts. What is the proper approach to be able to distinguish these two types of leafs? Create two subclasses of Node?
Rich
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between the two types of amounts? Is it only in the grouping?
 
Rich Smyth
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The two type of amounts are used to explain how the same total may be broken down two different ways.
All other totals have only one possible break down and therefore a single child type.
A distinction must be made between the leafs only for reporting purposes, otherwise the attributes are the same.
 
Your mother was a hamster and your father was a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic