Java Performance Services
Training, Seminars, Benchmarking, Tuning

Java Performance Tuning Course


Chania Crete, May 17-20, 2010


Sun Extreme Learning EXL-2025

Houston, December 1-4,2009
New York, December 8-11, 2009
Washington DC, January 5-8, 2010



San Francisco, January 11-14

Anti-if

I have joined Anti-IF Campaign

Calendar

««Nov 2009»»
SMTWTFS
1234
5
67
891011121314
15161718192021
22232425262728
2930

Performance Anti-Patterns

My Top Tags

                                       

Mailing List

My RSS Feeds








A Dry Conversation

posted Sunday, 27 June 2004
Exert from a recent chat: mudcat2727: are you the guy I know that hates Value Objects? kcpeppe: yup mudcat2727: so what would you suggest as a replacement to pass object-concept data across tiers? kcpeppe: the object kcpeppe: the problem is with EJBs kcpeppe: you have an entity that can only exists inside a container kcpeppe: so, how do you move state about? kcpeppe: in that environment kcpeppe: VO is the hack answer mudcat2727: ok mudcat2727: agreed kcpeppe: recognizing that the EB is just another container kcpeppe: frees you to move onto better solutions mudcat2727: ok kcpeppe: so create things that can be wrapped and can also move So, why do I hate Data Transfer Objects (DTO) previously known a value objects? The biggest reason is that they violate DRY; don’t repeat yourself. Value objects are a hack that serves to solve an artificial problem created by containers. The problem is the anti-pattern known as the revolving door. The revolving door refers to the back and forth communication that one needs to engage in while the gut the entity bean for it’s state (wow, a violation of encapsulation to boot). Plain and simple, this is a very expensive way to move an objects state from one place to another. The hack, create a class that gathers up state (sans behavior) and carries it to the caller in a single shot. So, now we have two different classes that are repeating the same purpose, to hold onto state. DRY is not the only principle being violated but, that is a topic for another day.



1. a reader left...
Monday, 28 June 2004 9:58 pm

If not VO, then what?

Using a VO does not mean keeping state in two places. I use a VO and DAO where the DAO is a SQL, XML, or File reader and never stores state, therefore no state problems. In fact, none of the containers on the back side in my system store state. I just don't like it as a design. The only state is held in the presentation-JSP tier.

So back to my original question, if not VO, then what? Is there something better?

Mica


2. a reader left...
Friday, 2 July 2004 12:04 am

It sounds like to me, Kirk (and forgive me if I'm mistaken), that you aren't against the concept of a model object specifically, but what you are saying is don't duplicate that model in the EJB and outside the EJB - instead view the EJB object as a wrapper around that standard model that specifically wires in container support. Then, use the internal representation for leaving the container. This gives the added benefit of having one object to rule them all, and it can hold deterministic behavior AND data. Is that about right?

R.J. [rjlorimer@coffee-bytes.com]


3. Kirk Pepperdine left...
Friday, 2 July 2004 8:17 am

R.J.

I know wish that I have said it your way :)

Mica, you are keeping state in two different places. That is what a VO is for but to hold state for an object that you can't move. Why not just move the object it'self?

Seperating state from behavior means that you will have to marry the two some time in the future. This means that you either have to move the state back into the original object (which is necessary when one uses a relation DB to persist an object), or you have to duplicate that behavior in something else. There are execeptions as you have pointed out with the JSP example. That said, frameworks that support parallel hierarchies IMHO have always been difficult to use, fragile, and difficult to maintain. Where as techniques such as serialization which do not rely on parallel hierarchies are much simplier to use,are much more robust and are very easily maintained.


4. a reader left...
Friday, 2 July 2004 5:16 pm

Kirk,
I guess I'm pretty think-headed. I don't understand what you mean by moving the object. If I use a SQL class to get model object data, pass references to the tiers, all the while storing state data about the object in the object and only there, is that not 'moving' the object and not storing state in two places? The JSP tier stores state data in the VO thru JSP Bean references so that data is not duplicated.

Please explain moving.

Also, if you hate DTO, what do you use?

Thanks :)

Mica


5. Kirk Pepperdine left...
Friday, 2 July 2004 7:13 pm

Well, you do have to copy data when you move it between tiers but you still can move the domain object instead of having to transfer state and then move that object and then retransfer state into something else.