0 Replies Latest reply on Jan 28, 2003 5:13 PM by Volkmar

    Design issue - how to perform business methods

    Volkmar Newbie

      Hi everyone,

      First of all: this is a design question, nothing to do with a JBoss-specific problem/issue. Disregard this post at your discretion :o)

      I need to decide on how to implement business methods/financial calculations in my J2EE app. The way I see it, there are two discussion-worthy approaches to calculating, e.g. an order total.
      The first approach would be in accordance with the Expert pattern: a bean knows how much services rendered by itself will cost (as specified in the data member variables), and it knows how many times these services were requested. Furthermore, the bean knows which beans are related to it (via the home interfaces and lookup methods), so it can iterate through all its dependent beans and their dependent beans. In other words, a "calculateGrandTotal" method called at the 'top' of the relational entity tree will cascade down, call all the "calculateLocalTotal" methods in turn, and then add them up to get the total.
      The second approach I thought of was to encapsulate all financial calculations in their own package, and to basically create one long (and unfortunately quite complicated) SQL statement which will essentially do the same.
      My 'hunch' is that the first approach is probably more maintainable and easier to adjust. We are not overly concerned with speed, so sacrificing speed for maintainability and clarity is definitely an option for us. With an efficient caching mechanism and a fairly large bean pool, it shouldn't create a 'performance hit' when instantiating all beans related to an order.
      The only reason I am doubtful of the first approach is that it seems excessive to instantiate a bean (which has the potential do to much more than just calculate a number) JUST to do precisely that. This seems like a bit of a waste of processing time, no matter how much hardware power one has available.
      Therefore I thought it might also be appropriate to calculate totals with a big SQL statement for each bean for performance's sake.

      Your thoughts on this are greatly appreciated !

      Best regards,

      Volkmar