Professional Documents
Culture Documents
J2Ee Platform Design Patterns For Enterprise Applications: Inderjeet Singh Mark Johnson
J2Ee Platform Design Patterns For Enterprise Applications: Inderjeet Singh Mark Johnson
J2Ee Platform Design Patterns For Enterprise Applications: Inderjeet Singh Mark Johnson
Inderjeet Singh
Mark Johnson
J2EE BluePrints
Sun Microsystems, Inc.
2333, J2EE Platform Design Patterns for Enterprise Applications
Why Design Patterns?
—Freeman Dyson
• Capture expertise
• Form a common design vocabulary
• Make designs more transparent
for newcomers
• Facilitate restructuring of existing systems
• Consequences
– Clarifies design by separating class roles
– Enables multiple data views/multiple users
– Simplifies system extension, impact
analysis, and deployment
– Enhances extensibility and testability
– Eases maintenance by decreasing
code replication
– Can partition developer responsibilities
• Implementation Strategies
– Carefully analyze communication volume
and latency to ensure scalability
– Potential maintenance problem if Model
API is in flux
• Controller usually written in terms of Model
• Consider applying Command or Facade
pattern to decouple Controller from Model
– Abstract components can not use each
others’ implementation details, so
efficiency may be suboptimal
14 2333, J2EE Platform Design Patterns for Enterprise Applications
Front Controller
receives input,
FrontController dispatches events,
selects views
• Consequences
– Separates request processing logic
from response generation logic
– Centralizes request processing
– Simplifies security and logging
– Unsuitable for small applications or for
web sites with a lot of static content
• Implementation strategies
– In Web tier, implement as a servlet
– Use Command pattern to effectively
organize request processing and
manage complexity
– Use with XML-based GUI templates
SessionFacade
• Consequences
– Centralizes application interface
– Decouples tiers and developers
– Supports thin client development
– Hides data model complexity from clients
– Single point of control for security, logging
– Adds an additional level of indirection
– May duplicate API
– Possible complexity hazard
21 2333, J2EE Platform Design Patterns for Enterprise Applications
Session Facade (Cont.)
• Implementation Strategies
– Implement as a session bean in the EJB™ tier
– Create a web-tier proxy for the session bean
– Prefer stateless session bean where possible
– Use Session Facade for a set of Use Cases
accesses
BusinessObject DataAccessObject
inherits inherits
adapts adapts
• Consequences
– Resource type independence
• Database, directory server, connector, etc.
– Resource vendor independence
• CloudscapeDAO, OracleDAO, etc.
– Enhanced extensibility
– Easier migration to CMP
– Increased complexity: Extra classes
• Can be generated by tools
• Implementation Strategies
– Apply Factory pattern to create DAO instances
– Make them pluggable by using deployment
descriptor entries or Java Naming and
Directory Interface™ (JNDI) names
– Generated DAO layer improves reliability
instantiates
WebComponent
• Consequences
– Reduce network traffic and improve response
time for coarse-grained, read-only data
– Can be cached
– Extra classes add complexity
– Need to handle stale value objects
• Implementation Strategies
– Serializable
– Provide immutable and mutable versions
– Should be relatively small
remote access
EJBObject
• Consequences
– Provides efficient access to read-only
data, transactional access for updates
– Duplicates functionality, increases
complexity
– Nontransactional reads inappropriate
for data that change often
• Implementation Strategies
– DAO must contain all methods that
require efficient access
– Prefer declarative transaction control
iteratively
accesses PageByPage accesses
ClientObject EntityList
Iterator
• Consequences
– Efficient access to large lists on the server
– Potentially higher number of server hits
• Implementation issues
– Trade-off between network transmission
load and server hit frequency
– Page size may be client-dependent
– Pages must be serializable
– Caching can improve user experience
and decrease network load
– Apply with Fast Lane Read pattern
Account
Order
Profile
Shopping
Cart
Session Facade
Front Controller
Catolog Browser
Web Component
Customer Data
Access Object
Customer
Entity Bean
DAO
(web-tier) EJB EJB EJB EJB
Fast Lane
Reader Session Facade
Controller
Efficient read only access Simple
Value API
EJB Controller
Page-by-Page Object
Iterator
Coarse Front Controller
Navigate large GrainedObject
result sets View
Navigation
Web-Tier Single Point
of entry
View
Browser
—C. A. R. Hoare
46 2333, J2EE Platform Design Patterns for Enterprise Applications
2333, J2EE Platform Design Patterns for Enterprise Applications
48 2333, J2EE Platform Design Patterns for Enterprise Applications