This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
hi im quite new to struts so i hope i can get some answers from the gurus. is it common to put the business logic inside the action classes (as in many examples) or should the action just call the apropriate methods of the business logic ? if the actions just call methods of the b-logic, then how do they get a reference to it ? whats a common way to do this (since the perform method and the constructor of the aciton is fixed) ? well thats it for now....i hope somebody here can help me. thanks a lot karl
Originally posted by karl koch: is it common to put the business logic inside the action classes (as in many examples) or should the action just call the apropriate methods of the business logic ? if the actions just call methods of the b-logic, then how do they get a reference to it ? whats a common way to do this (since the perform method and the constructor of the aciton is fixed) ?
Hi Karl, I'm fairly new to struts myself, but I'll let you know what I've learned from my research/coding thus far: It depends on who you ask, but there seems to be a consensus that the Action classes are typically considered part of the Controller, not the Model, so it is best not to place business logic in the Actions. From what I have seen, the recommended course of action is to code to an interface and use a pattern such as a Facade or a Factory to gain references to your business tier classes. This will effectively decouple your Model from your Controller, which is what you want with MVC2. The methods exposed by the interface to the business logic can(and often do) return Value Objects representing the state of the business tier, which your Views then display. These are my impressions of what I have read and the strategy I employ in my code, somebody please feel free to correct me here if I am giving bad information! E
My theory of evolution is that Darwin was adopted. - Steven Wright
Joined: May 25, 2001
eric thanks a lot for your reply. i thought so too. separating the controller from the logic/model is a good idea. do you have any good resources, a full struts example ? the examples if found (at least the ones with documentation) were small "hello world" like apps. there all the logic is inside the action. thanks again. karl
Joined: Oct 26, 2000
I've found full Struts examples hard to come by, but About Struts is a great site, lots of info and tips, and an example application that I haven't gotten around to downloading yet. The best references I've found yet have been recently published books like "Struts in Action" by Ted Husted(who also runs the About Struts site) and "Programming Jakarta Struts" by Chuck Cavaness. Both really good books. HTH, E