• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Use of adapter pattern to decouple

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am looking at using object adapters to decouple my domain model from my presentation tier. Our initial strategy was to take the domain objects, and convert those to DTO's that would be used by the jsp servlets to build the pages. I was thinking about creating adapters that would have the domain object as a constructor argument and attribute, and the getters would access the values from the domain object to build the page. I believe this would require serialization of the argument domain object (and associated objects), which could be costly?.

The way I see it I have three possible approaches:
1. Go with the adapter pattern, and potentially serialize a lot of objects,
2. Have DTO's that take a domain object as a parameter, then load the attributes of the DTO,
or
3. Create a "factory" that builds the DTO's?

Any input would be greatly appreciated.
Thanks.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I usually figure DTOs are a necessary evil, used only when imposed by inter-component protocols in some architectures. Which makes the architecture at least malevolent if not evil. If you can avoid them, do so.

What's wrong with the presentation layer knowing about the domain model? Sounds perfectly natural. Traditional MVC and its ilk all make sure that the domain model is not aware of the presentation layer. That's usually the important bit.

I could make up a requirement that would lead us to an adapter, but it would be pretty unusual. Are you sure you have one?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are your domain model and the presentation tier running in different VMs?

If not, I agree with Stan - I wouldn't see a problem with the presentation tier working directly on the domain model.
 
Acetylsalicylic acid is aspirin. This could be handy too:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic