Data Transfer Object Conventions
Data Transfer Objects Convention Definition:
The Proper Use of C# Plain Old CLR (or C#) Objects (POCO) as Method State Return Objects and Other State Management Object Types
Data Transfer Objects Convention Justification:
A Data Transfer Object (DTO) is a C# Class which encapsulates State Property Object.
DTOs Provide a Decoupling Mechanism Between Layers in an Architecture Design
Almost all Behaviour Methods, called from a higher level Software Entity, requests processed data that can be encapsulated within a DTO.
Generally a higher level module sends a Request DTO, with the parameter data encapsulated within the DTO, and expects a Response DTO with encapsulated result data.
DTO Standards Provide a Vehicle that Ensures that all DTOs are Managed in a Uniform Fashion
Data Transfer Objects Convention Standards:
- Web Page View Request DTO – Passes View page Query String data and common property data to the Service layer for Request processing
- Service Layer Request DTO – Passes mapped View Request information, both Query String and Common data, to the Service Layer for Response processing.
- Service Layer Response DTO – Passes Service request Composite information along with Error handler data to the calling Software Entity
- Web Page View Response DTO – Passes information, generally a subset of DTO Response data, to a View page as a Strongly Typed Model State Object. All Error handler data for a “One and Only One” Web page usage is part of the aggregate collection.
- Helper Method Parameter DTOs – Encapsulates Method constructor parameters for Helper Method signatures. This supports the Open / Closed principle by abstracting away the details of the parameter collection from the calling Method. It also helps to manage code Noise and clutter by eliminating lengthy method parameter strings.
DTOs can be an Aggregate DTO or a Composite DTO
- An Aggregate DTO holds Primitive Types and other Aggregate DTOs as DTO member types.
- An Aggregate DTO has no Real Domain Object value unto itself.
- An Aggregate has Real Domain value only when a member of a Composite DTO.
- A Composite DTO is a Domain Entity that contains all the Property Members required to serve a Business Object Function.
- A Composite DTO has Domain Value as a State Object.
- A Composite DTO contains Member Types that are Primitive and Aggregate DTOs.
- A Composite DTO can be a Member of a Higher Level Composite DTO.
Data Transfer Objects Manage the State of Data in Enterprise Applications.
DTO Anatomies
1. The RequestCommon DTO – A Base State Object that holds common properties that can be passed to lower level module layers. Request DTOs pass method specific parameter data that is encapsulated within the State Object Class. This base object can have initialization logic that ensures that properties are populated correctly but should not contain any Behaviour methods unless those methods goes to the intent of the base classes “Cross Cutting Concerns”. It also may need to pass state data that is common to all Request DTOs. These data properties are usually consumed by “Cross Cutting Concern” services required by an Enterprise Application. These concerns could be:
a. Logging Services
b. Messaging Services
c. Security Services
d. Authorization and Authentication Services
e. Deployment Configurations
f. Database settings that change with various deployment environments.
2. Composite View Request State Object – A DTO, with its base DTO, encapsulates Query String parameters sent by a Web page View in an MVC design pattern. This collection, along with the Base DTO collection, creates the complete DTO. This DTO is used to Request information from Databases and Service Layers. Logging Services for the View Request DTO is processed through asynchronous calls from the base DTO object. The required data properties from the Base View Request DTO are mapped to the Service Request DTO for processing on the Services Tier.
3. Composite Service DTO Request State Object – A DTO, with its base DTO, encapsulates Service Request parameters. The Service DTO base object supports the property data required for Cross Cutting Concerns such as logging. The derived Composite DTO is consumed by the Service Request Method as required parameters for the return Service Response DTO.
1. The IErrorCommon Interface – An Interface that is implemented by the Response DTO that holds a List of Error objects for the returning Response DTO through Interface Extension Methods. The Interface has a Success Flag and an Error List Property that is a List<ErrorInfo> Objects containing:
a. Error Messages – String messages that can be custom messages from a Messages System database source or Exception messages from the Exception Class.
b. Stack Trace – string information populated from an Exception object
2. Composite Service DTO Response State Object – A Composite DTO, with its Error handler, which encapsulates Service Response Aggregate DTOs. This Composite DTO contains primitive and string root level properties along with other Composite DTOs acting as Aggregates for the Composite DTO. Collections of Aggregate DTOs are managed by List<T> properties.
3. Composite View Response DTO State Object – A Composite DTO created for exclusive information results for delivery to a Client such as a Web View page in the MVC design pattern. This DTO is populated by data that is mapped from a Response Service DTO and created for a “One and Only One” result as a Strongly Typed model for a View page in the MVC design pattern. It is requested by an MVC Controller method and delivered to the View page with the error handling data intact for processing within the Web View page.
1. A simple DTO Composite POCO Class that encapsulates the parameter list.
2. Offers an extension object for parameter changes without the calling method requirement for additions to the constructor parameters.
3. Manages Method Intent by abstracting away details not generally required for understanding the underlying intent of the calling method.
1. Decouples the of required information from the sources of that information
2. Provides encapsulation of Complex Data Objects that are Open for Extension without modifying acquisition process for the consuming Software Entity
3. Provides performance value by enabling the Just-In-Time (JIT) compiler to process these objects as POCO objects rather than code blocks in memory
-
DTOs should be pure State Objects, No Behavior Methods.
-
They hold the current State value for Properties defined within the State Class.
-
Collections of other DTOs are called Aggregate DTO Collections.
-
Aggregate DTOs are lower level State objects that generally represent lower level primitives and string types.
Latest posts by Brad Huett (see all)
- DevOps: A Bridge to Your DevOps Culture - March 25, 2016
- Embracing Test Driven Development (TDD) - March 25, 2016
- DevOps: Delivering Agile Projects - March 25, 2016