Re: [ljc] DTO as an anti-pattern?

From: Gerald L.
Sent on: Friday, January 11, 2013 9:31 AM
The answer lies in the relationship of the triangle consisting of the clients of your webservice, the webservice itself, and the DB/entities:

if 
1. all clients can at all times be kept in sync with the webservice (as the latter evolves) 
and
2. the DB schema and JPA entity definitions behind the webservice are at all times optimised for the purposes of the webservice only (as opposed to also having to serve the needs of other apps or components)
then you don't need the decoupling that DTOs buy you - otherwise you do.

  cheers
  gerald

On Friday, January 11, 2013, Craig Silk wrote:
There's a good amount of talk about DTO's being pointless and / or DTO's being essential and a part of a well designed, loosely coupled architecture. I think both points are valid but that does leave me wondering which direction to take.

I'm taking data from a database and ultimately passing it through a web service for consumption elsewhere. My persistence layer / domain models are JPA entities annotated with JAXB annotations so the data can be marshaled into XML before being passed to the web service (this is managed by an EJB application that sits between the web services and the domain models).

I'm constantly bugged by the thought that I should be using data transfers objects (POJO's with getters and setters) to hold the data from the entities and use JAXB annotations (in the DTO's) to create the XML payload.

So my question is: use DTO's or not?

Pros
- Separation of concerns, are entities really the right place to stick JAXB annotations anyway?
- Cheerry picking data, I can create smaller DTO's that hold a subset of what an entity returns thus making it easier to marshal XML payloads with less data.

Cons
- The cost associated with replicating data.
- Breaking the DRY principle.
- Have to introduce optional annotations (and logic) that tell JAXB what  to NOT marshal... does this break the KISS principle?

I would usually turn to Martin Fowler in my times of Architectural need but I've got limited web access today.

Thanks
Craig




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Craig Silk ([address removed]) from LJC - London Java Community.
To learn more about Craig Silk, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]


--
Gerald Loeffler
mailto:[address removed]
http://www.gerald-loeffler.net

Our Sponsors

  • Our Blog

    Read the latest news from the LJC

  • RecWorks Ltd

    Fixing Tech Recruitment using the Power of Community

  • jClarity

    Java/JVM Performance Analysis Tools & mentoring for Java related matters

  • LJC Aggrity

    Our LJC Aggrity site contains blog posts from our members

  • LJC Book Club

    Our Book club with book reviews from our members

  • Devoxx UK

    Java Community Conference, in collaboration with the LJC 12/13 Jun 14

  • SkillsMatter

    "Host, help organise, promote, film many of our meetings."

  • New Relic

    New Relic makes sense of billions of metrics a day in real time.

  • Hazelcast

    Hazelcast is the leader in operating in-memory computing.

  • Java.Net

    We are an official Java User Group recognised by Oracle's JUG program

  • JRebel

    Free 3 month J-Rebel license.

  • O'Reilly

    40% discount on printed books and 50% on e-books.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy