File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "JavaBeans or Transfer Object?" Watch "JavaBeans or Transfer Object?" New topic

JavaBeans or Transfer Object?

Chris Bicnal
Ranch Hand

Joined: Aug 17, 2005
Posts: 80
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?



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

Joined: Oct 30, 2007
Posts: 47

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.

I agree. Here's the link:
subject: JavaBeans or Transfer Object?
It's not a secret anymore!