This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

DTO Setter Best Practises  RSS feed

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Abu Nene
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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, ...?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!