Entity Translator
Entity Translator
Retired Content
The Web Service Software Factory is now maintained by the community and can be found on the
Service Factory site.
This content is outdated and is no longer being maintained. It is provided as a courtesy for
individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or
pages that no longer exist.
Context
A distributed application sends and receives messages with remote agents. The request
and response messages being transferred exist in code as classes and contain serialization
rules for their state between network nodes.
Within the business logic tier, a domain model exists that contains classes that represent
entities in the system. These classes may not contain serialization rules.
Problem
Problem
How do you transform entity objects from one type to another?
Forces
Any of the following conditions justifies using the solution described in this pattern:
Solution
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.
Participants
Entity translation involves the following participants:
Business entity. This is a class used to represent a domain model entity within the
business tier of an application.
Data contract. This represents a data structure used by the service interface.
Service interface. The service interface provides operations that use data contracts
for request and response messages.
Entity translator. The translator is responsible for converting between data contracts
and business entities.
Transaction script. This is a class that processes incoming requests from the service
interface and, if necessary, returns a response.
The diagram in Figure 1 identifies the relationship between participants in this pattern.
Figure 1
Relationship between participants in the Entity Translator pattern
Process
Entity translation consists of the following high-level tasks:
Incoming data contracts are translated into a business entity. The entity translator
creates an instance of the business entity and initializes it with data from one or more
data contracts.
Outgoing business entities are translated into a data contract. The entity
translator creates an instance of the data contract and initializes it with data from one
or more business entities.
1. The entity translator provides a function that takes one or more data contract classes
as parameters and returns a specific business entity.
2. Within the implementation of the function, a new instance of the business entity is
created and initialized using data from the data contract classes.
3. After a new instance of the business entity has been initialized, it is returned to the
application that made the request.
Business Entities Are Translated into a Data Contract
1. The business controller returning a response can use a function on the entity
translator that takes one or more business entities as parameters and returns a
specific data contract required by the service interface. This is accomplished by
creating an instance of the data contract and initializing it with data from the business
entities.
2. After the data contract is initialized, it will be sent to the service interface that made
the original request.
Resulting Context
This section describes some of the more significant benefits, liabilities, and security
considerations of using this pattern.
7 Note
Benefits
The benefits of using the Entity Translator pattern include the following:
Liabilities
The liabilities of sing the Entit Translator pattern incl de the follo ing:
The liabilities of using the Entity Translator pattern include the following:
Data can be lost between translations when translated data types do not support all
of the fields found in the original data types.
It may be necessary to call multiple translators during a single action, which can
increase complexity by requiring process dependencies on consumers of the
translator. This can be mitigated by using a process manager pattern.
Implementation of an object-based solution requires the creation of custom objects
that have to be maintained. As the number of data types increase, the maintenance
requirements of entity translators will also increase.
Security Considerations
To perform translations, the data must be deserialized and accessible. This requires that
any encrypted messages be decrypted before calling the translator.
Example
The service interface of a banking solution uses data contracts for input parameters and
return values for service actions. The business tier that provides an implementation for the
service interface uses business entities. To process requests in the business tier, data
contracts must be translated into business entities. Business entities included in a response
from the business tier have to be translated into data contracts.
The UML sequence diagram in Figure 2 illustrates the interaction of objects used to
implement an action that returns customer information:
Figure 2
Interaction of objects used to implement the Entity Translator pattern
Related Patterns
The Entity Translator pattern is similar to the Message Translator pattern described in
Integration Patterns: Designing, Building, and Deploying Messaging Solutions by Gregor
Hohpe and Bobby Woolf.
Acknowledgments
Hohpe, Gregor, and Bobby Woolf. Integration Patterns: Designing, Building, and Deploying
Messaging Solutions. Addison-Wesley, 2004.