• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why not pass ActionForm instance to Model

 
Vijay Raj
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Why shouldn't we pass ActionForm instances to the Model. I read somewhere that it causes high coupling. If true, so what.

I am not able to understand the practical dis-advantages of passing an ActionForm instance. What problems may it cause?

regards,
vijay.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a scenario that might help explain it:

Say you decide to ignore the advice and pass your ActionForms as parameters to your model classes. Everything will work great, all is well, life is good.

Until.....

Your boss or client comes to you and says, "The CEO read in a airline magazine that JSF with AJAX is really the way to go, and Struts is really out of date. I want you to convert this application to JSF and Ajax."

You're thinking: OK, it's cool, I've used Model/View/Controller. I can just take the Model code that I've written and plug it into a JSF view.

Wrong!!

Since you made your Model class dependent on a Struts class (org.apache.struts.action.ActionForm) as soon as you remove struts.jar from your project, the model classes will no longer compile. You now have the choice of leaving the struts.jar file in the project just to make the project compile, or change your model classes.

The moral of the story: Tightly coupling your model classes with Struts or any other view framework is a bad thing.
[ July 05, 2006: Message edited by: Merrill Higginson ]
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OMG! I have my every model extend ActionForm and did something like...

public class Applicant
{
NameFormBean name;
ApplicationInfoFormBean applicationInfo;
}

where all those members extend ActionForm!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic