Quantcast
Channel: Question and Answer » web-services
Viewing all articles
Browse latest Browse all 136

Assembler vs Entity Translator and Entities vs DTO

$
0
0

I was hoping that someone could explain the exact difference between an Assembler and Entity Translator.

Martin Fowler describes the Assembler as a sort of Mapper(?) which converts DTOs into Domain objects and vice versa.

When you’re working with a remote interface, such as Remote Facade
(388), each call to it is expensive. As a result you need to reduce
the number of calls, and that means that you need to transfer more
data with each call. One way to do this is to use lots of parameters.
However, this is often awkward to program – indeed, it’s often
impossible with languages such as Java that return only a single
value.

The solution is to create a Data Transfer Object that can hold all the
data for the call. It needs to be serializable to go across the
connection. Usually an assembler is used on the server side to
transfer data between the DTO and any domain objects.

However, this description sounds very similar to the Entity Translator.

“Implement an entity translator that transforms message data types to
business types for requests and reverses the transformation for
responses.

The entity translator is an object that is tightly coupled to message
data types and business entities, while providing loose coupling
between the consumers of the types. In other words, components of an
application use the translator to transform data types and the
translator has no knowledge about operations provided by the
application. This behavior provides the ability to change data types
on either end of the interaction without requiring changes to the
other end. The only component that needs to be updated is the
translator itself”

So this is a little bit confusing.

The reason why I’m asking this question is because I’m currently building out a client library which will allow me to retrieve/send data through remote REST API; however as I map this response data into my DTOs I had considered creating an additional anti-corruption(?) layer which will then map those DTOs into my Domain Models.

Basically, I would like to distribute these libraries via composer as a prepackaged module but still have the flexibility to swap them out should I find something better.

Another question I’d like to ask is how to differentiate between Entities + DTOs since Entity is a term which is often brought up whenever I discuss Data Mappers(which is how I’m currently structuring my client libraries). Although I just referred to them as DTOs; the term “Entity” is often used to describe the type of objects you would either pass into or retrieve via the Data Mapper.

I suppose it’s possible that I’ve been using Active Record pattern for far too long but the two of them basically just look like Anemic Domain Models me – ie: just getters and setters.

How do I properly distinguish between the two?


Viewing all articles
Browse latest Browse all 136

Trending Articles