DynaDTO Dynamic Data Transfer Objects - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

DynaDTO Dynamic Data Transfer Objects

Description:

Typical Patterns in a J2EE Web Application. The Transfer ... Service Locator. Transfer Object. Composite Entity. Transfer Object Assembler. Value List Handler ... – PowerPoint PPT presentation

Number of Views:269
Avg rating:3.0/5.0
Slides: 39
Provided by: briansa9
Category:

less

Transcript and Presenter's Notes

Title: DynaDTO Dynamic Data Transfer Objects


1
DynaDTO Dynamic Data Transfer Objects
  • Brian Sam-Bodden
  • Integrallis Software, LLC.

2
Presentation Contents
  • J2EE Patterns
  • Typical Patterns in a J2EE Web Application
  • The Transfer Object Pattern
  • The Transfer Object Assembler Pattern
  • Transformation Layers in J2EE
  • Typical DTO Strategies
  • Problems with existing DTO strategies
  • The DynaDTO strategy
  • Typical Usage Scenarios
  • Configuring DynaDTO
  • Using DynaDTO

3
J2EE Patterns
  • Abstractions of a Solution (design) to a
    recurring problem
  • Refactoring Good Design Time Design Pattern
  • Patterns are discovered, not created
  • J2EE Patterns are
  • Strategies
  • Interpretations
  • Extensions
  • of more general design patterns (GoF)

4
J2EE Patterns
  • Each pattern (design) can have multiple
    implementations (strategies)
  • The trick is...
  • ... finding the right granularity for your
    problem
  • ... collaboration amongst patterns
  • Pragmatic View
  • A practical solution to a real world recurring
    problem and the guidelines of when and where to
    apply it

5
J2EE Patterns
  • J2EE Pattern Catalog Pattern Format
  • Problem
  • Forces
  • Solution
  • Structure
  • Interaction
  • Consequences
  • Strategies

6
J2EE Patterns
  • J2EE Pattern Catalog classifies patterns by Tier
  • Presentation Tier
  • Business Tier
  • Integration Tier

7
Presentation Tier Patterns
  • Intercepting Filter
  • Front Controller
  • Composite View
  • View Helper
  • Service to Worker
  • Dispatcher View
  • Context Object
  • Application Controller

8
Business Tier Patterns
  • Business Delegate
  • Session Facade
  • Service Locator
  • ? Transfer Object
  • Composite Entity
  • ? Transfer Object Assembler
  • Value List Handler
  • Business Object
  • Application Service

9
Integration Tier Patterns
  • Data Access Object
  • Service Activator
  • Domain Store
  • Web Service Broker

10
J2EE Patterns
11
Typical Patterns in a J2EE Web Application
  • Presentation Tier
  • MVC Model II OR Component-based MVC like
  • JSPServlet, Struts, JSF, Tapestry and others
  • Business Tier
  • POJO Domain Model
  • Domain Model persistence via DAO
  • DAO wraps persistence mechanism (JDBC, CMP, JDO,
    Hibernate)
  • Services in Session Façade
  • Services return and take DTOs

12
Typical Patterns in a J2EE Web Application
  • Business Tier (cont.)
  • DTOs are assembled from Domain Objects
  • Assembly step is manual

13
The Transfer Object Pattern
  • Also known (old) as Value Object Pattern
  • The Problem
  • Coarse-grained Entities
  • CMP EJBs not meant to leave the Tier they live in
  • Each data access (method call) is a potentially
    remote call
  • Performance degradation, portability problems,
    brittle architecture

14
The Transfer Object Pattern
  • The Problem (cont.)
  • Fine-Grained Entities
  • Domain Model should not be exposed to the client
  • Client needs are temporal (application specific)
  • Domain should outlive client needs and be
    reusable
  • Anemic Domain Model (Fowler) results from Domain
    Model tainted by both Data Model and the User
    Interface Needs
  • No separation of concerns, lack of encapsulation

15
The Transfer Object Pattern
  • The Problem (cont.)
  • Bulk-Transfers
  • Not only for the data of a single entity
  • Collections Transfer
  • Support for pagination schemes

16
The Transfer Object Pattern
  • The Forces
  • Web Applications are typically read-mostly and
    save/update-occasionally
  • Data Viewing requirements per page are
  • Typically composed of multiple attributes
  • Transformed for display purposes

17
The Transfer Object Pattern
  • Solution (typical)
  • Transfer Object to encapsulate business data
  • Single method call to transfer data of a business
    entity
  • Business Tier Code (Enterprise Bean) constructs
    the Transfer Object, populate and pass it by
    value to the client

18
The Transfer Object Pattern
19
The Transfer Object Pattern
20
The Transfer Object Pattern
  • Strategies
  • Updateable Transfer Objects Strategy
  • Multiple Transfer Object Strategy
  • Entity Inherits Transfer Object Strategy (1-to-1)
  • Transfer Object Factory Strategy
  • Custom Transfer Object Strategy
  • Multiple Entity, Single Transfer Object

Not in the J2EE Pattern Catalog Entry
21
Typical Implementation
  • Developers manually create light(er) weight
    objects
  • Populate them in code, near where they access the
    data
  • Session Façade, Entity Bean, DAO
  • Usually support strategies outlined poorly
  • Requires a great deal of coding
  • Muddles the business tier with transformation
    code
  • Equivalent to having O/R mapping code

22
Problems with the Typical Implementation
  • Parallel-Object Hierarchy
  • Parallel Hierarchy is hard to maintain
  • in XP terms this is smelly
  • Sign that domain has been flattened
  • Code Overhead/Maintenance
  • DTO classes
  • Transformation Code

23
Transformation Layers in J2EE
  • In a typical 3 tier application there are 2
    transformation tiers
  • Between the business tier and the
    data/integration tier
  • Between the business tier and the presentation
    tier
  • O/R Mapping Tools deal with the first
  • DTO Pattern Implementations deal with the second
  • Problem is that everyone starts from scratch

24
The DynaDTO Solution
  • Provide a solution to the screen/UI object lt--gt
    domain/data object transformation problem
  • Solution similar to what Hibernate is to O/R
    Mapping
  • XML configuration
  • Factory-based design
  • Smart defaults
  • Supports all the strategies for the DTO pattern
    well
  • Enables you to test outside of the container

25
A DynaDTO Sample Usage Scenario
  • We have a single object, want a mirror DTO
  • A Quote object is the domain object
  • The interface IQuouteDTO represents the DTO
  • Client only reads IQuoteDTO

26
A DynaDTO Sample Usage Scenario
  • Quote.java
  • public class Quote
  • // fields
  • private String title
  • private Date date
  • private String author
  • String text
  • // getters and setters

27
A DynaDTO Sample Usage Scenario
  • IQuoteDTO.java
  • public interface IQuoteDTO extends DTO
  • String getTitle()
  • Date getDate()
  • String getAuthor()
  • String getText()

28
A DynaDTO Sample Usage Scenario
  • IQuoteDTO.dto.xml
  • lt?xml version"1.0"?gt
  • ltdtosgt
  • ltdto targetIQuoteDTO"gt
  • ltsourcesgt
  • ltsource typeQuote" automap"true" /gt
  • lt/sourcesgt
  • lt/dtogt
  • lt/dtosgt

29
A DynaDTO Sample Usage Scenario - 2
  • We have an object graph with 3 objects
  • A Conference object
  • A Conference has a Venue object
  • A Conference has Tracks

30
A DynaDTO Sample Usage Scenario - 2
  • We want a IConferenceSummaryDTO interface
  • Read only
  • Some info from the Conference object
  • The address, broken in two lines from the Venue
    object
  • A List with the names of the Tracks

31
A DynaDTO Sample Usage Scenario - 2
  • IConferenceSummaryDTO.dto.xml Shell
  • lt?xml version"1.0"?gt
  • ltdtosgt
  • ltdto targetIConferenceSummaryDTO"gt
  • ltsourcesgt
  • ltsource typeConference" gt
  • ...INTERESTING STUFF GOES HERE
  • lt/sourcegt
  • lt/sourcesgt
  • lt/dtogt
  • lt/dtosgt

32
A DynaDTO Sample Usage Scenario - 2
  • IConferenceSummaryDTO.dto.xml
  • ltsource type"Conference"gt
  • lt!-- aliases, used by the expressions --gt
  • ltalias source"venue" name"venue" /gt
  • lt!-- mappings --gt
  • ltmapping from"name" to"conferenceTitle" /gt
  • ltmapping from"venue.name" to"venueName" /gt
  • ltmapping from"venue.address.streetAddress
  • to"venueAddressLine1" /gt
  • lt/sourcegt

33
A DynaDTO Sample Usage Scenario
  • IConferenceSummaryDTO.dto.xml
  • ltexpressionsgt
  • ltexpression target"VenueAddressLine2
  • value"venue.getAddress().getCity() ','
    util.space()
  • venue.getAddress().getState()
    util.space()
  • venue.getAddress().getZipCode()
    " /gt
  • lt/expressionsgt

34
Steps to use DynaDTO
  • Define your DTO Interfaces
  • Create mappings from Domain Object to DTO
    interfaces
  • Reference the mapping in the dynadto.cfg.xml
  • At runtime, initialize DynaDTO by reading
    dynadto.cfg.xml
  • To create a DTO, use BuilderFactory to get a
    Builder for a given DTO interface or class
  • Gather your source (domain objects)
  • Pass them to the build method of the builder

35
DynaDTO Sample Configuration File
  • dynadto.cfg.xml
  • lt?xml version"1.0" encoding"utf-8"?gt
  • ltdynadto-configurationgt
  • lt!-- mappings --gt
  • ltmapping resource"ConferenceSummary.dto.xml" /gt
  • lt/dynadto-configurationgt

36
Initializing DynaDTO
  • dynadto.cfg.xml
  • try
  • ConfigurationLoader.loadConfiguration("dynadto
    .cfg.xml")
  • catch (ConfigurationException ce)
  • ce.printStackTrace()

37
Using DynaDTO
  • Conference conf ...
  • // build the DTO
  • Builder builder BuilderFactory
  • .getInstance()
    .getBuilder(IConferenceSummaryDTO.class)
  • IConferenceSummaryDTO myDTO
  • (IConferenceSummaryDTO) builder.build(conf)

38
Conclusions
  • DynaDTO simplifies implementation of DTO Pattern
  • Supports all known strategies
  • Supports complex expressions
  • Supports nested DTOs
  • Supports Collection Flattening/Transformation
  • Allows you to use POJIs or POJOs as DTOs

39
THANK YOU
  • Questions?
  • Feel free to email me at bsbodden_at_integrallis.com
Write a Comment
User Comments (0)
About PowerShow.com