Best practise - Domain model design

Hello forum,

we're writing an application divided into three sub projects where one of the sub projects will be realized using J2EE and the other two sub projects are stand alone fat client applications realized using Swing. So that's the background...

And now the questions:

After doing some research on J2EE best practise topics I found the TransferObject-Pattern (http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html) which we certainly want to apply to the J2EE sub project and to one of the standalone client applications also. To avoid code duplications I like the "Entity Inherits Transfer Object Strategy" approach outlined in the document referenced above. But why does the entity bean inherit from the transfer object class and not vice versa? In my opinion the tranfer object adds additional functionality (coarse grained getData()-method) to the class and isn't it a design goal in OO languages that the class that extends a base class has more functionality than the base class?

For the standalone application we want to use a similar approach and the first idea is to desgin the entitys and let the TO classes extend these entitys.

When I get it right the basic idea behind all of these design schemes is the "Proxy pattern" but when I design it using the previously mentioned way (Entity <-- EntityTO) I will have a very mighty prox beeing able to execute all operations the base class is able to execute.

Any tips and comments welcome!

Thanks in advance!

Henning

[1563 byte] By [hm@collogiaa] at [2007-10-3 9:20:27]
# 1

> But why does the entity bean inherit from the transfer object class and not

> vice versa?

Because the client shouldn't be aware that there are entity beans. The client should only work on the super class. I.e the transfer object. You wouldn't be able to return different implementations from your factory if the entity bean was the super class.

Kaj

kajbja at 2007-7-15 4:33:46 > top of Java-index,Java Essentials,Java Programming...
# 2
.. You can also think of it as this. An entity bean is a special case of transfer object. A transfer object is not a special case of entity bean.Kaj
kajbja at 2007-7-15 4:33:46 > top of Java-index,Java Essentials,Java Programming...
# 3

Hello Kaj,

at first - thanks for your fast response and sorry for coming back to this topic so late.

After reading a bit more on patterns in general what about avoiding inheritance

completely and using the proxy pattern instead (As explained eg.

http://www.javaworld.com/javaworld/jw-02-2002/jw-0222-designpatterns.html here) - so moving the design to a "has a" relationship rather than an "is a" relationship.

In the previous post you said that the client shouldn't be aware that there are entity beans and therefore the mentioned implementation was chosen - But if I implement it vice versa (Entity is base class, TO extends entity) and do not expose any of the methods of the entity bean I would achieve the same effect, or not? Clients are only able to work with the TOs.

I have some headaches implementing it in SUN's recommended way because of the Serialization support necessary within the TOs. Implemented in SUN's way the Entity bean would also have serialization support which isn't necessary because they're persisted using Hibernate.

Thanks in advance

Henning

hm@collogiaa at 2007-7-15 4:33:46 > top of Java-index,Java Essentials,Java Programming...