Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is Composite pattern appropriate ?

 
Rich Smyth
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic