O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for a Transfer Object?

If it’s likely that a business service might be asked to send or receive all or most of its data in a big, coarse-grained message, it’s common for that service to provide that feature in its API. Commonly, the business service creates a serializable Java object that contains lots of instance variables. Sun calls this object a Transfer Object. Outside of Sun there is a pattern called Data Transfer Object. Guess what? They’re the same thing. (Yeah, we feel the same way about that.)

image with no caption

The client’s perspective, inside the Business Delegate:

image with no caption

That’s it. Under the covers, the Transfer Object is serialized, shipped, and deserialized on to the client’s local JVM heap. At that point, it is just like any other local bean.

Note

The data in a Transfer Object grows stale!

Once it’s shipped across the network, the Transfer Object is completely out of touch with its source, and begins to fall out of sync with the state of the data in the underlying database. You’ll have to decide for each use case whether data integrity/synchronization is worth the performance hits.

Service Locator and Business Delegate both simplify model components

Listen in as our two black-belts debate which pattern is better—Service Locator or Business Delegate.

Service Locator is the superior pattern. First ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required