[EMAIL PROTECTED] wrote:

Hi Bob, I'll try to give my 1 cent to the topic and also to answer you more concrete because I believe you want some concrete answers, not theoretical conversations.

Background: I just started a Struts project with Hibernate.  I have chosen to 
use the Data Access Object with (Abstract Factory) design pattern because my 
client uses Oracle and I use Postgresql database.  I am working with other 
teams remotely and they decided to use DTO.

Why do you mention DTO and DAO here together? I think that they are known solutions for very different problems ... (at least my opinion is that DTO doesn't have anything to do with DAO) Btw, Hibernate abstracts already your access to the database (i.e. doesn't matter if it's Oracle or Postgres unless you use some special features from these RDBMS). Just change the driver settings in the hibernate.cfg.xml and it will work transparently with chosen RDBMS.

Problem: A few months ago, I recall a message thread on this list with a subject header of: 'DTOs are evil'. Since I am new to this, I am having problems understanding why. I thought that DTO are for data storage and data transfer between Business and Value Objects.
Questions: I have the following questions:

1. Why I shouldn't choose it?
You will use them even if you don't want - ActionForms are DTOs. They just save you the work to translate the request parameters in more convenient form. You can consider also HttpServletRequest as DTO. ActionForms also have some validation functionality, but I almost never use it (except for the most simple cases).

2. Should I be using the Apache Commons BeanUtils in my action?  It has a 
method like BeanUtils.copyProperties(...).
Personally, I use BeanUtils all the time, because it saves me a lot of writing. If your forms change very often i.e. you add/change/delete fields to/from them, then I recommend you mapped forms - a form with a map and all BO properties are copied from BO to this form map and vice versa. The difference is also how do you use the map in jsp tags - instead of writing something like this <html:text property="city"/> you have to write it <html:text property="mapvalues(city)"/> When I use mapped forms I can change very fast the whole content of a form because the changes are only in 2 places (where they should be) - in the BO and in the jsp. If you use "normal" ActionForms any change will force you to touch other 2 files: the struts-config.xml and derived ActionForm class.

3. If not BeanUtils, then what do you recommend?


Thanks,

Bob

The best way is just to try 2-3 different approaches and see what are the advantages and disadvantages of every one. Then you can decide how and when you can use them all or only one. Or say it in other way - first find and define unambiguously what are you problems and then search the appropriate solution.

Regards
Borislav

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to