• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Pass Data Between Model and Action

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes when my Actions delegate tasks to some POJO classes in the Model, I need to transfer a set of closely related data e.g. a few primitives + a class+ a Collection. It seems that the "proper" OO design is to create a specific DTO class just for the purpose of returning data from Model to the Controller. This is acceptable if the model is remote like EJB. But is there any simplier way to avoid creating new classes just for the purpose of returning a set of data?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34656
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alec Lee:
It seems that the "proper" OO design is to create a specific DTO class just for the purpose of returning data from Model to the Controller.

Yes. This is the way I would do it.

But is there any simplier way to avoid creating new classes just for the purpose of returning a set of data?

Why do you want to avoid creating an object? It does have a purpose - as you noted: to transfer data.

The alternative is using a Map, but then you lose type safety. In my mind, this is much less productive and less maintainable than creating the object. In an IDE, creating a new object and generating the getters/setters doesn't take long at all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic