Java Reference
In-Depth Information
Lack of encapsulation of the domain model
In a design that uses DTO s, the presentation tier simply has no access to the
domain objects and so cannot bypass the EJB façade and call them directly. Fur-
thermore, the structure of the DTO s does not have to mirror the structure of the
domain objects. As a result, the business tier can be changed without impacting
the presentation tier. You could even replace a domain model with transaction
scripts without affecting the presentation tier. In comparison, when using a POJO
façade the presentation tier accesses the domain objects directly and so there is an
increased risk of it being affected by changes to the business tier. Later in this
chapter I'll show you how to partially encapsulate the domain objects and mini-
mize the impact of changes by using interfaces.
Some domain object methods cannot be called by the presentation tier
Another limitation of detached objects is that some methods cannot be called by
the presentation tier. Although many domain object methods return the value of
a field or perform simple calculations, others are much more complicated. For
example, a PendingOrder method could define a getDiscount() method that
retrieves a discount schedule from the database. If the presentation tier invoked
one of these methods, the persistence framework would throw an exception
because the connection is closed when the POJO façade returns. To avoid this
problem, the POJO façade must call those methods while the database connection
is open and return a DTO -like object that stores the computed values.
7.1.4
When to use a POJO façade and detached domain objects
The POJO façade should be used when:
The business logic does not participate in transactions initiated by remote
clients.
The application uses a lightweight container.
The client can get the façade from the lightweight container.
The business logic requires a consistent view of the database.
The domain objects can be easily detached and can be invoked by the pre-
sentation tier.
Now that we have looked at the benefits and drawbacks of a POJO façade, let's
look at various design decisions that you must make when using one.
 
 
 
 
 
 
Search WWH ::




Custom Search