File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes JavaBeans or Transfer Object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "JavaBeans or Transfer Object?" Watch "JavaBeans or Transfer Object?" New topic
Author

JavaBeans or Transfer Object?

Chris Bicnal
Ranch Hand

Joined: Aug 17, 2005
Posts: 80
    
    1
Hi everyone,

Being from a J2EE background I've architected my application in a tiered manner (GUI, business and data).

Each layer communicates to the one below via an interface I've defined (so there are two interfaces in total).

In all methods I only pass one parameter as I'm employing the transfer object pattern, but I have a question about that....

Should I pass objects between my methods that are JavaBeans (with getters and setters for every field) or is a POJO with publicly exposed attributes OK?

The reason I ask is that's it's a pain calling the get and set each time you want to get or set a value and I think it makes the code more difficult to read. But I'm concerned if I omit the getters and setters I could get marked down for not encapsulating my data...

Any ideas?

What's everyone else done?

Thanks,

Chris

PS Not that it matters, but I'm doing B&S...
David Winters Junior
Ranch Hand

Joined: Oct 30, 2007
Posts: 47
Chris,

I use a getter/setter method on each of the attributes like a JavaBean class definition. It is good practice defining private attributes and public methods to access those attributes therefore using encapsulation which im sure you know all about.

David
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaBeans or Transfer Object?