j2ee pattens

52
Concise Group Limited J2EE Patterns : Part 1, the Business Tier

Upload: rajanikantsingh

Post on 25-Jul-2016

16 views

Category:

Documents


0 download

DESCRIPTION

J2EE book

TRANSCRIPT

Page 1: J2EE Pattens

Concise Group Limited

J2EE Patterns : Part 1, the Business Tier

Page 2: J2EE Pattens

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

Page 3: J2EE Pattens

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

Page 4: J2EE Pattens

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

Page 5: J2EE Pattens

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

Page 6: J2EE Pattens

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

Page 7: J2EE Pattens

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

Page 8: J2EE Pattens

What are Patterns?

Page 9: J2EE Pattens

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

Page 10: J2EE Pattens

Why do we need them?

Page 11: J2EE Pattens

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

Page 12: J2EE Pattens

J2EE Architecture

Page 13: J2EE Pattens

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

Page 14: J2EE Pattens

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

Page 15: J2EE Pattens

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

Page 16: J2EE Pattens

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

Page 17: J2EE Pattens

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

Page 18: J2EE Pattens

Patterns for the Business Tier

Overview

Page 19: J2EE Pattens

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

Page 20: J2EE Pattens

Patterns for the Business Tier

Value Object

Page 21: J2EE Pattens

Value Object

• Reduce the number of fine grained remote method calls

EJB container

Remoteentity bean

Client Get information

Get information

Get information

Get information

Page 22: J2EE Pattens

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

Page 23: J2EE Pattens

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

Page 24: J2EE Pattens

Patterns for the Business Tier

Session Façade

Page 25: J2EE Pattens

Session Façade

• Reduce the number of remote method calls

Entity beans

EJB container

Client

Page 26: J2EE Pattens

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

Page 27: J2EE Pattens

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

Page 28: J2EE Pattens

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

Page 29: J2EE Pattens

Patterns for the Business Tier

Composite (or Aggregate) Entity

Page 30: J2EE Pattens

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

Page 31: J2EE Pattens

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

Page 32: J2EE Pattens

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

Page 33: J2EE Pattens

Patterns for the Business Tier

Service Locator

Page 34: J2EE Pattens

Service Locator

• Reduce the number of remote look ups

Lookup

Application Server

Client

Enterprise JavaBeans

Lookup

Lookup

JNDI

ContextContext

ContextContext

ContextContext

Page 35: J2EE Pattens

Service Locator

• Reduce the number of remote look ups– Adopt the Service Locator Pattern

Application Server

Enterprise JavaBeans

ServiceLocator

JNDIContextContext

ClientLookup

Lookup

Lookup

Page 36: J2EE Pattens

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

Page 37: J2EE Pattens

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

Page 38: J2EE Pattens

Patterns for the Business Tier

Business Delegate

Page 39: J2EE Pattens

Business Delegate

• Tight coupling between presentation and business tier

EJB container

Client

EnterpriseJavaBean

Page 40: J2EE Pattens

Business Delegate

• Tight coupling between presentation and business tier– Adopt the Business Delegate Pattern

EJB container

Client

DelegateDelegateEnterpriseJavaBean

Page 41: J2EE Pattens

Summary

Page 42: J2EE Pattens

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

Page 43: J2EE Pattens

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

Page 44: J2EE Pattens

References and further reading

• Design Patterns– Addison Wesley, Dec 1994– ISBN 0201633612

Page 45: J2EE Pattens

References and further reading

• Core J2EE Patterns– Prentice Hall, June 2001– ISBN 0130648841

Page 46: J2EE Pattens

References and further reading

• Designing EnterpriseApplications with J2EE– Prentice Hall, June 2000– ISBN 0201702770

Page 47: J2EE Pattens

References and further reading

• EJB Design Patterns– Wiley, February 2002– ISBN 0471208310

Page 48: J2EE Pattens

References and further reading

• Professional EJB– Wrox Press, July 2001– ISBN 1861005083

Page 49: J2EE Pattens

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

Page 50: J2EE Pattens

Questions, comments and feedback?

[email protected]

Page 51: J2EE Pattens

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]

Page 52: J2EE Pattens

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