4

given the deprecation of loads of design patterns because of the new improvements in the Java EE world, DTO's are largely frowned upon.

However, I dont want the relational structure of database to dictate how the client(web app) uses the services in my EJB. Because of the way technology evolves, I see work being done in about 5 years time in trying to overhaul the UI as fibre optic technologies and other unthinkables becoming a reality. So i want the business logic to be completely encapsulated to allow easily changing the UI whenever we want.

With this thinking in mind, i am developing a pure api to represent the business model and services so the client can use that instead.

However, I'm having to write converters all the time to convert the entity beans to this API. Is this the right thing to do or am over engineering.

Your feedback and opinion largely welcomed.

NB. This project uses the full Java EE 6 platform

Farouk Alhassan
  • 3,780
  • 9
  • 51
  • 74

1 Answers1

2

There are conflicting "religions" about the best way to proceed. I, like you, prefer more object-oriented solutions, which means that DB rows (entities) are not equal to business domain objects. So, what to do?

I'd recommend using your typical tooling, e.g. Hibernate or Spring, to populate entities in your persistence layer. Then, use brokers to move state between the DB and the domain layer classes/objects.

HTH, Mark

Mark
  • 1,988
  • 2
  • 24
  • 42
  • 2
    Should have mentioned, you can read more here: http://martinfowler.com/bliki/AnemicDomainModel.html – Mark Feb 21 '11 at 14:54
  • Thanks for the response. i also think that what I am doing is the most logical thing to do. Will just watch out and see if I find anything anemic or redundant and refactor accordingly apart from the converters ofcourse – Farouk Alhassan Feb 21 '11 at 16:11
  • I struggle to find the best solution as well. In some cases you can use inheritance. The base class is the public class and the subclass is the class used internally. This will allow you to hide some things but it definitely is not a perfect solution. – Pace Feb 21 '11 at 18:34
  • 1
    @Mark Does this mean that you use Entity beans for both the database access and the business domain objects, or is there some other structure we should be using for the domain objects? – Bill K Jul 05 '11 at 21:19