File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes DTO Setter Best Practises Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "DTO Setter Best Practises" Watch "DTO Setter Best Practises" New topic
Author

DTO Setter Best Practises

Abu Nene
Ranch Hand

Joined: Nov 13, 2008
Posts: 56
Hi all, in my current situation, I've DTO which there alot of attributes to be populated and the implementation should be reuseable by other class with the same DTO.

Any advice on what is the best practises approach for this. I can't consider object relational mapping as there is performance issue.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Welcome to JavaRanch.

I would say the best practice would be to use the standard Java Bean setter/getter naming convention. For each property, create a setter named 'setPropertyName with the property name capitalized. so a property of 'userName' would have a setter named 'setUserName'. For getters, name the getter 'getPropertyName for all non-boolean properties and 'isPropertyName for any boolean properties. For example for a property of 'userName' would have a getter of 'getUserName'. A boolean property of authorized would have the methods 'setAuthorized' and 'isAuthorized'.

This is the standard in Java and will be one most familiar to other developers. Plus, there are a lot of libraries out there that use reflection to allow for accessing properties that follow this naming convention.

See http://en.wikipedia.org/wiki/JavaBean and http://www.unix.com.ua/orelly/java-ent/jnut/ch06_02.htm for some more info.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1763
    
    7

Originally posted by ABu NeNe:
Any advice on what is the best practises approach for this. I can't consider object relational mapping as there is performance issue.


Is that statement based on fact or assumption? Provided you use an ORM framework correctly - and avoid common pitfalls - you'll be hard-pressed to implement a custom data access layer that will significantly outperform any popular ORM framework for all but the simplest of domain models.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Abu Nene
Ranch Hand

Joined: Nov 13, 2008
Posts: 56
Let me further explain myself.



If I were to get a J2EE DAO design pattern to set the attribute of this MyDTO.



Are there any best practise on implementing the myDTO.setA, ...?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DTO Setter Best Practises