File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Is Composite pattern appropriate ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Is Composite pattern appropriate ?" Watch "Is Composite pattern appropriate ?" New topic
Author

Is Composite pattern appropriate ?

Rich Smyth
Ranch Hand

Joined: May 30, 2002
Posts: 87
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

Joined: Jul 11, 2001
Posts: 14112
What is the difference between the two types of amounts? Is it only in the grouping?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rich Smyth
Ranch Hand

Joined: May 30, 2002
Posts: 87
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
 
subject: Is Composite pattern appropriate ?