J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

21
J2EE Architecture and Design Patterns Student: Fang Fang Advisor: Dr. Glen Qin Date: 05/14/2005

description

 

Transcript of J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Page 1: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

J2EE Architecture and Design Patterns

Student: Fang FangAdvisor: Dr. Glen Qin

Date: 05/14/2005

Page 2: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Agenda

● Introduction to “Architecture”

● J2EE Architecture Diagram

● Distributed Programming Serviced

● Modular-Based Development

● J2EE Application Deliverable

● J2EE Standards

● Patterns Arose from Architecture

● Gang of Four Patterns

● Q & A

Page 3: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Introduction to Arthitecture

● Architecture is the overall structure of a system, and it can contain subsystems that interface with other subsystems

● Architecture versus Design (level of details)

● Architecture considers bunch of *abilities

CapabilityAvailabilityReliabilityManageability and FlexibilityPerformanceScalabilityExtensibility, Validity, ReusabilitySecurity

Page 4: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

J2EE Application I J2EE Application II

Client tier

Web tier

Business tier

EIS tier

Clientmachine

J2EEServermachine

DataBaseServermachine

ApplicationClient

Dynamic HTML pages

JSP/Servlet

EnterpriseBeans

DatabaseDatabase

EnerpriseBeans

Multi-tiered J2EE applications

Page 5: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Distributes Programming Services

● Naming and Registration (JNDI)

● Remote Method Invocation (RMI)

● Protocols

● Distributed Object Frameworks

Between user interface and business tiers HTTP, RMI, CORBA, DCOM, JMS

Between business and persistence tiers JDBC, IDL to COM bridge, JMS, plain socket, native APIs via JNI embedded in resource adapters

- CORBA- Native Language Integration- Java/RMI- DCOM

● XML

Page 6: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

EJB Distributed Nature (I)

EJB Container

BeanEJBObject

EJBHome

Remote Stub

Home Stub

Client

Page 7: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

EJB Distributed Nature (II)

Page 8: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

J2EE Modular-Based Development

● Presentation tier developer

● Bean provider

● Application assembler

● Component provider

● Application server provider

● EJB container provider

Staff be categories into different roles:

Page 9: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

J2EE Application Deliverable

Web archive(.war)web.xml

EJB archive(.jar)ejb-jar.xml

Client archive(.car)application-client.xml

Enterprise archive (.ear)application.xml

Page 10: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Deployment Descriptor Sample

<ejb-jar> <enterprise-beans> ... </enterprise-beans> <assembly-descriptor> <security-role> <description> This role represents everyone who is allowed full access to the Cabin EJB. </description> <role-name>everyone</role-name> </security-role> <method-permission> <role-name>everyone</role-name> <method> <ejb-name>CabinEJB</ejb-name> <method-name>*</method-name> </method> </method-permission> <container-transaction> <method> <ejb-name>CabinEJB</ejb-name> <method-name>*</method-name> </method> <trans-attribute>Required</trans-attribute> </container-transaction> </assembly-descriptor></ejb-jar>

Page 11: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

J2EE Standards

● CTS

● J2EE SDK

Contains following specs

Together with below's offerings

● EJB spec

● Servlet spec

● JSP spec

Page 12: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Patterns Arose from Architecture and Anthropology - Christopher Alexander

● Is quality objective?

● How do we get good quality repeatedly?

● Look for the commonalities

● ...especially commonality in the features of the problem to be solved

Page 13: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Moving from Architectural to Software Design Patterns

● Adapting Alexander for software

● The Gang of Four did the early work on design patterns (Gamma, Helm, Johnson, Vlissides)

Page 14: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Key Features of Patterns

Item Description-------------------------------------------------------------------------------------------------------------Name All patterns have a unique name that identifies themIntent The purpose of the patternProblem The problem that the pattern is trying to solveSolution How the pattern provides a solution to the problem in the context in which it shows upParticipants The entities involved in the patternand collaboratorsConsequences The consequences of using the pattern. Investigates the forces at play in the patternImplementation How the pattern can be implementedGeneric structure A standard diagram that shows a typical structure for the pattern

Page 15: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Enumerate GoF Patterns

Structural Patterns

AdapterBridgeCompositeDecoratorFacadeFlyweightProxy

Behavioral Patterns

Chain of ResponsibilityCommandInterpreterIteratorMediatorMementoObserverStateStrategyTemplate MethodVisitor

Creational Patterns

Abstract FactoryBuilderFactory MethodPrototypeSingleton

Page 16: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Abstract Factory Pattern

“Provide an interface for creating families of related or dependent objects without specifying their concrete classes." - GoF

Solution

A Switch to Control Which Driver to Use

class ApControl { . . . public void doDraw() { . . . switch (RESOLUTION) { case LOW: // use lrdd case HIGH: // use hrdd } } public void doPrint() { . . . switch (RESOLUTION) { case LOW: // use lrpd case HIGH: // use hrpd } }}

Problem class ApControl { . . . public void doDraw() { . . . myDisplayDriver.draw(); } public void doPrint() { . . . myPrintDriver.print(); }}

abstract class ResFactory { abstract public DisplayDriver getDispDrvr(); abstract public PrintDriver getPrtDrvr();}

class LowResFact extends ResFactory { public DisplayDriver getDispDrvr() { return new LRDD(); } public PrintDriver getPrtDrvr() { return new LRPD(); }}class HighResFact extends ResFactory {...}

Page 17: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

The Facade Pattern

● “Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.” - GoF

Problem Solution

Page 18: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

Stragegy Pattern

Solution

“Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.” - GoF

Problem

Page 19: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

J2EE Best Practice – MVC Pattern (I)

● Model

● Controller

● View

Represents the application data along with methods that operate on that data.

Displays that data to the user.

Translates user actions such as mouse movement and keyboardinput and dispatches operations on the Model.

Page 20: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

J2EE Best Practice – MVC Pattern (II)

Http requestor post

Response

Forward

Dispatch

Update

Extract

Client browser

Controller(action servlet)

Businesslogic

Model(server sideJavaBean/EJB)

View(JSP page)

Page 21: J2EE Architecture and Design Patterns - Northwestern Polytechnic ...

● Q & A● Thank you!!