Two Laptop Bag*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Problem in calculating financial objects with cyclic dependencies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Problem in calculating financial objects with cyclic dependencies" Watch "Problem in calculating financial objects with cyclic dependencies" New topic
Author

Problem in calculating financial objects with cyclic dependencies

Maciej Opala
Ranch Hand

Joined: Jul 18, 2011
Posts: 38
Hi,
I've the following problem and need a piece of advice in design.

There are two classes of business objects from financial domain: A and C, and A contains a collection of C. An user may request to calculate (refresh the indexes, recalculate the debt and so on) the objects of this classes. The problem is that A requires some data from the collection of C to be fully calculated and C, also requires some data from A to be fully calculated. Currently, all the calculations are done in on class , fortunately not in one method. This design is in conflict with clean code principle (the code is very messy and unclear) and I'd like to refactor the code. The problem lies in the two-way dependencies.

My idea is to create AbstractCalculator class which will hold the currentlyCalculatedA and other common fields that are required for calculation (configuration, info-services). Then I will create ACalculator and CCalculator that both extend AbstractCalculator, also ACalculator has an instance of CCalculator.
Then in ACalculator:
- A is calculated till possible
- Collection<C> is calculated with usage of CCalculator
- A is calculated till the end
- the state of AbstractCalculator is reseted and waits for the next calculation.

Here is the diagram:




Will it be good designed or maybe someone has a better idea?


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in calculating financial objects with cyclic dependencies