j2ee pattens
DESCRIPTION
J2EE bookTRANSCRIPT
Concise Group Limited
J2EE Patterns : Part 1, the Business Tier
About me
• Technical Architect with Concise– [email protected]
• Been using Java since 1996• Sun Certified
– Enterprise Architect for J2EE– Web Component Developer for J2EE– Developer for the Java 2 Platform
• Presented several BOFs at JavaOne• Presented at several JSIG seminars• Published on JavaWorld.com
About me
• Co-wrote Professional JSP (2nd edition)• Co-wrote Professional Java Servlets 2.3
• Involved in reviewing– Beginning JSP Web Development– Professional Java SOAP– Early Adopter JSP Standard Tag Library
Announcing…
• Professional JSP Tag Libraries– Wrox Press, April 2002– ISBN 1861006217
• Table of Contents– JSP Tag Extensions– Simple Tags– Tag Body Content– Scripting Variables in the Page– Iteration Tags– Body Tags– Cooperating Tags– Tag Patterns (including Custom Tags vs.
JavaBeans)– Designing Tags and Tag Libraries– Deployment– A Case Study– Third Party Tag Libraries
About Concise
• Java and J2EE solutions provider– BEA WebLogic– IBM WebSphere– RUP and other methodologies
• Services include– Technical architecture– Technical consultancy– Project delivery– Skills/knowledge transfer– Mentoring
Abstract
The Sun Java Centre (SJC) has recently catalogued a number of patterns that provide solutions to frequently encountered problems in the design and implementation of J2EE applications. This includes patterns for increasing performance and also helping provide internal structure for increased maintainability and reusability of components.
"Core J2EE Patterns" (Prentice Hall, 2001) describes these patterns in detail and is an excellent reference guide but can seem overwhelming to start with. This, the first of two sessions, presents a simplified look at the major patterns that are relevant to designing the business tier of J2EE applications. The session will illustrate how the following patterns can be applied to the development of Enterprise JavaBeans in your J2EE applications:
· Value Object · Session Façade · Composite (or Aggregate) Entity · Service Locator · Business Delegate
Introduction and roadmap
• What are patterns?• Why do we need them?• J2EE architecture• Patterns for the business tier
– Value Object– Session Façade– Composite (or Aggregate) Entity– Service Locator– Business Delegate
• Q&A
What are Patterns?
Patterns
• Design patterns can be an important tool when designing software– they capture re-usable solutions to common problems– provide a common language with which to describe them
• Address different aspects of design and development– Structure, creation, behaviour, performance, scalability
• J2EE patterns catalogue– Solutions to problems frequently encountered when
building J2EE systems– Covers presentation, business and integration tiers
Why do we need them?
Why do we need them?
• Possible to build complex systems without patterns– Problems not tackled in a consistent manner– Inconsistency increases maintainability
• Patterns do tend to increase the initial complexity• An important tool for
– Structuring applications in a proven and consistent way
• Increases maintainability– Easier to get to grips with a system based around
familiar solutions• Also a common language
– Written and verbally
J2EE Architecture
A Typical J2EE Architecture
• A typical J2EE architecture logically, and physically separates– Server-side presentation
» JavaServer Pages and Java Servlets
– Application logic» Session beans
– Business object model» Entity beans
– Enterprise information systems» Relational databases, LDAP, etc
A Typical J2EE Architecture
Presentation tierUser interface generation, lightweight validation
Business tierHeavyweight processing, validation, business rules, workflow and interfaces to external systems
Persistence tierData transformation and persistence services
J2EE application server
A Typical J2EE Architecture
Java Servlets and JSPsUser interface generation, lightweight validation
Session BeansHeavyweight processing, validation, business rules, workflow and interfaces to external systems
Entity BeansData transformation and persistence services
J2EE application server
A Typical J2EE Architecture
J2EE application server
JavaServer PagesJavaServer Pages Java ServletsJava Servlets
JavaBeans
Session beans
Entity beans
RM
I/IIOP
Web browser HTTP
Web browser HTTP
DatasourceJDBC
Web/EJB container
A Typical J2EE Architecture
Datasource
J2EE applicationserver
Session beans
Entity beans
JDBC
Web browser
Web server
JavaServer PagesJavaServer Pages
Java ServletsJava Servlets
JavaBeans
Static content(HTML, images, etc)
Static content(HTML, images, etc)
HTTP
RMI/IIOP
Web browser HTTP
Web/EJB container
Patterns for the Business Tier
Overview
Best practices and patterns
• There are many pitfalls when building J2EE solutions– Too many remote network calls reduces
performance– Too many fine-grained entity beans reduces
performance– Too many fine-grained remote methods increases
network overhead
Patterns for the Business Tier
Value Object
Value Object
• Reduce the number of fine grained remote method calls
EJB container
Remoteentity bean
Client Get information
Get information
Get information
Get information
Value Object
• Reduce the number of fine grained remote method calls– Adopt the Value Object pattern
Value objectValue object
Value objectValue object
Value objectValue object
EJB container
Client
Remoteentity bean
Value Object
• Don’t use EJB finder methods for displaying large numbers of objects– Adopt the Data Access Object pattern with Value
Objects
Value objectValue object
EJB container
Client
DataAccessObject
JDBCValue objectValue objectValue objectValue object
Value objectValue object
Value objectValue object
Value objectValue object
Value objectValue object
Value objectValue object
Datasource
Patterns for the Business Tier
Session Façade
Session Façade
• Reduce the number of remote method calls
Entity beans
EJB container
Client
Session Façade
• Reduce the number of remote method calls– Adopt the Session Façade pattern
• Session bean as a façade
Session beanEntity beans
Client
EJB container
Session Façade
• Reduce the number of remote method calls– Adopt the Session Façade pattern
• Session bean as a mediator
Session beanEntity beans
EJB container
Client
Session Façade
• Granularity of session beans– Business process?– Use case?– Screen on the user interface?
• A rule of thumb is to group related functionality, for example– Business logic around inserting, updating and
deleting a customer
Session bean with customer related functionality Customer beans
EJB container
Client
Patterns for the Business Tier
Composite (or Aggregate) Entity
Composite (or Aggregate) Entity
• Reduce number of remote method calls and lifecycle management overhead for container
Application Server
Client
Entity bean
Entity bean
Entity bean
Composite (or Aggregate) Entity
• Entity beans should be used “sparingly”– 1-to-1 mapping between entity beans and database
tables can impact performance» high number of remote method calls» high lifecycle management overhead for container
– therefore define coarse grained entity beans» dependent entities as JavaBeans
JavaBean
ManagesRemote
entity bean ManagesJavaBean
Composite (or Aggregate) Entity
• Reduce number of remote method calls and lifecycle management overhead for container– Adopt the Composite Entity Pattern– Adopt Local Interfaces
Application Server
Client Local Entitybean
Entity bean
JavaBean
Patterns for the Business Tier
Service Locator
Service Locator
• Reduce the number of remote look ups
Lookup
Application Server
Client
Enterprise JavaBeans
Lookup
Lookup
JNDI
ContextContext
ContextContext
ContextContext
Service Locator
• Reduce the number of remote look ups– Adopt the Service Locator Pattern
Application Server
Enterprise JavaBeans
ServiceLocator
JNDIContextContext
ClientLookup
Lookup
Lookup
Service Locator
• Reduce the number of remote look ups– Adopt the Service Locator Pattern
Application Server
Enterprise JavaBeans
ServiceLocator
JNDIContextContext
JMS TopicJMS Topic
JMS QueueJMS Queue
JDBC DataSourceJDBC DataSource
ClientLookup
Lookup
Lookup
Service Locator
• For convenience, split the responsibility– Adopt an EJB Home Locator and a Service Locator
Application Server
Enterprise JavaBeans
JMS TopicJMS Topic
JMS QueueJMS Queue
JDBC DataSourceJDBC DataSourceServiceLocator
EJB HomeLocator
JNDI
ClientLookup
Lookup
Patterns for the Business Tier
Business Delegate
Business Delegate
• Tight coupling between presentation and business tier
EJB container
Client
EnterpriseJavaBean
Business Delegate
• Tight coupling between presentation and business tier– Adopt the Business Delegate Pattern
EJB container
Client
DelegateDelegateEnterpriseJavaBean
Summary
Summary
• Java/J2EE is a great platform for large, distributed component based developments– portable– high performance and scalable– integration with existing systems– rapid development with the new wave of tools– massive industry support
• Patterns are an important tool in design and development– Increases maintainability– Provides common solutions and a common
language
Summary
• J2EE patterns have come out of the SJC and the developer community– Solutions to problems frequently encountered when
building J2EE systems– Covers presentation, business and integration tiers
• Business tier patterns include– Value Object– Session Façade– Composite Entity– Service Locator– Business Delegate
References and further reading
• Design Patterns– Addison Wesley, Dec 1994– ISBN 0201633612
References and further reading
• Core J2EE Patterns– Prentice Hall, June 2001– ISBN 0130648841
References and further reading
• Designing EnterpriseApplications with J2EE– Prentice Hall, June 2000– ISBN 0201702770
References and further reading
• EJB Design Patterns– Wiley, February 2002– ISBN 0471208310
References and further reading
• Professional EJB– Wrox Press, July 2001– ISBN 1861005083
References and further reading
• Javasoft– http://java.sun.com– http://java.sun.com/j2ee/– http://java.sun.com/blueprints/– *http://developer.java.sun.com/developer/technicalArticles/J2EE/p
atterns/
• Others– http://www.theserverside.com– http://www.javaworld.com
* Free registration required
Questions, comments and feedback?
Simon Brown
Simon Brown is a Technical Architect with Concise and has been using Java since 1996. During this time he has been involved with many Java developments, acting as technical lead, mentor and trainer. Outside of work he has spoken at several Java events including JavaOne, has been published on JavaWorld and co-authored the 2nd edition of Professional JSP (Wrox Press) and more recently, Professional Java Servlets.
Simon graduated from the University of Reading in 1996 with a First class BSc (Hons) degree in Computer Science. He has also attained many Sun Certifications, including the Enterprise Architect for J2EE, Web Component Developer for J2EE and Developer for the Java 2 Platform.
Feel free to e-mail any questions or comments to [email protected]
Concise Group Limited
We are a Java 2 Enterprise Edition (J2EE) solution provider, focused on building, implementing and running highly robust and scalable business-to-business applications.
For more information please see our website at www.concise.co.uk