views:

72

answers:

1

Hi, I'm strating out web programming in Java and I want to know the best practices. I'm wondering where should my computations reside in let's say a Java MVC app or a Struts apps?

+4  A: 

It depends on the kind of computation. Most computations belong in the model, because most computations are tied to the data contained in the model.

But sometimes you need to compute something in a view (say, for example, you need to determine if there are enough items in a list to justify flipping to an alternate page format).

And sometimes they belong in the controller (maybe you need to determine which view to transition to based on controller-centric factors).

The real answer is, computations belong near the data they are tied to. Don't sum up account totals in the view, and don't compute font sizes in the model. Ommm.

MarkusQ
Wow thanks! I've learned something new :)
ajushi
BTW, what does Ommm mean?
ajushi
So shiuld I put coputations in beans?
ajushi