A domain model-centric approach to J2EE developmentcarfield.com.hk/document/software+design/Keiron+Domain+Model+Centric.pdf · A domain model-centric approach to J2EE development

Post on 25-Mar-2020

1 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

1

A domain model-centric approach to J2EE development

Keiron McCammonCTOVersant Corporation

2©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

OverviewOverview

nWhat is a domain model centric approach?nWhen should you consider using it?n How would you use it?uArchitectureuDesignuImplementationuEIS Integration

Patterns of Enterprise Application Architecture – Martin Fowler, at. al.

3©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

What

4©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Implementing Business LogicImplementing Business Logic

n Using objects to model the business domainnModel supports complex application logicuIts more than data validation/verification

n Persistence is secondary considerationuFocus is the business logic not the data

n Essentially its an OO application

Process-centric approach versus data-centricProcess-centric approach versus data-centric

5©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

When

6©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

DataData--centric centric vrsvrs ProcessProcess--centriccentric

Data-centricn Data-drivenn Adhoc query based,

decision supportn Record oriented, batch

processingn Wrapping existing

database

Process-centricn Process-drivenn Navigational accessn Complex application logicn Object-orientedn Building a new application

7©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Complexity of Business Logic

Com

plex

ity to

Impl

emen

t

Domain model-centric

Data-centric

8©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Pro’s & Con’sPro’s & Con’s

Pro’sn Fully leverage OO benefitsn Long term payoff as

application complexity increases

Con’sn Requires OO expertisen Higher cost of entry for

simply application

9©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

How

10©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Application Data & Enterprise DataApplication Data & Enterprise Data

n Application Data is the domain model objects, distinct from Enterprise DatauApplication data modeled as objectsuEnterprise data already exists in other systems

n Interact with application data and transact with enterprise datan Application data doesn’t need to leave the middle-

tier

11©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

What about the database?What about the database?

n Still need to persist application datan Interest is in storing/retrieving objects not

rows/columns

12©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Alternative SolutionsAlternative Solutions

n O/R Mapping Toolsn DAO Design Patternu http://developer.java.sun.com/developer/restricted/patterns/Dat

aAccessObject.html

n EJB 2.0 CMPn Java Data Objectsu http://jcp.org/jsr/detail/012.jspu Transparent object persistenceu Could use ODB as middle-tier databasel http://www.versant.com/products/enjin/index.html

3 Reduces coding effort5 Proprietary 5 Mapping overhead

5 Extra coding effort5 Mapping overhead

3 No coding effort3 Java standard3 Open choice of datastore

3 Reduces coding effort3 J2EE standard5 Mapping overhead5 Ease of use

13©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Contentious Conjecture…Contentious Conjecture…

“J2EE doesn’t offer much support fordomain model-centric applications”

14©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

How(Architecture)

15©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Business Users

ObjectRepository

PresentationLogic

BusinessLogic

Web ContentDelivery

EIS

Users

Clustering

Line of Business Systems

HTTP Servers

Load Balancing

Web A

pplication Servers

Application Servers

JSP/Servlet EJB

Java

XML/HTML XML

SOAP

UD

DI

Clustering

Firewall Firewall

DataW

arehouse

Data Migration

LDAP

Firewall

JCA/JDBC

16©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

How(Design)

17©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Domain Domain vrsvrs Component ModelsComponent Models

n Crucial to distinguish between Domain & Component modelsuDomain modellModels the data and relationships as Objects

u Component modellModels external, remote interfaces

n Merging the two leads to “fine grained” EJBs, every Java class being an EJBu Fine structure is too inefficient for heavy weight components

n Focus on “coarse grained” EJBsu Coarse structure diminishes benefits of OO approachu But good for defining interfaces & enterprise services

18©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Modeling the DomainModeling the Domain

n Data ObjectsuObjects that represent “real-world” entitieslCustomer; Order; Product

uAnd their relationshipslCustomer “can have many” Orders

n Built using Java ClassesuLight-weightuIntra-VM access only

http://martinfowler.com/eaaCatalog/domainModel.html

19©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Modeling the ComponentsModeling the Components

n Enterprise Java BeansuInterfaces that represent interactionslA customer “can place” an Orderl Provides a view or “façade” onto the domain model

uAnd their enterprise servicesl Security; naming; transaction management

n Built using Enterprise Java BeansuHeavy-weightuInter-VM access, distributed

http://martinfowler.com/eaaCatalog/remoteFacade.html

20©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Component ModelDomain model

Account

Portfolio

Position

Trade

Instrument

Equity

0..*

0..*

1..*

AdminBeancreateCustomer()createInstrument()

Façade for Account/InstrumentSeparates business methods for managing domain model

AccountBeanmakeTrade()getPortfolioDetails()getTradeHistory()

Façade for AccountCustomer interactions, hides underlying navigational model

InstrumentBeangetAll ()getQuote()

Façade for InstrumentManipulates all Instruments, hides underlying inheritance model

Combines benefits of both Object modeling and EJB development

21©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

How(Implementation)

22©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Software LayeringSoftware Layering

n Separate implementation and isolate dependenciesuSimplifies development, testing, debug, maintenance

n Loosely-coupled componentsuIsolate client versus server-side classesuSimplifies distributed deployment

n Three main layersuModeluViewuControl

23©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Software LayersSoftware Layers

viewaccountexception

controlejbAccountControllerTraderControllerInstrumentController

modelAccountPortfolioPositionTradeInstrumentEquity

<<manage>>

<<representation>>

<<instantiate>>

Classes in this package do not depend on any external classes and are all serializable

24©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Model (Domain Object Model)Model (Domain Object Model)

n Data ObjectsuComplex data, complex data relationshipsuFine-graineduPersistent and transactional

n No business logicuMainly getters/setters

n Independent of View and Controller layersuAlthough may throw exceptions

25©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

package trade.model

26©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

View (External Data Interchange)View (External Data Interchange)

n Light-weight Java classesuSerializable, non-persistent, non-transactionaluSimple data and simple data relationshipsuIdeally immutableuNo external dependencies

n No business logicuMainly getters/setters

n Instantiated by Controller layer, representation of Model layer

http://martinfowler.com/eaaCatalog/dataTransferObject.html

27©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

package trade.view

28©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Control (Business Logic)Control (Business Logic)

n External InterfacesuBusiness LogicuCoarse-grained operations on domain modeluHandles persistence and transactions

nManages the Model Layer and instantiates the View Layer

29©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Control (cont’d)Control (cont’d)

n Implement business logic as normal Java classesuSimplifies unit testing and debugginguCan be re-used with JSP/Servlets

n EJBs layer on top of business logic classesuAdd inter-component interactionsuAdd transaction propagation/managementuSupports distributed deployment

30©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

package trade.control

31©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

package trade.control.ejb

32©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

ExceptionsExceptions

n Identify internal versus external exceptionsuInternal exceptions never thrown outside of Control

Layer

n External exceptions belong to View LayeruNo internal dependencies

33©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

package trade.view.exception

34©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

AccountSessionBean

Account

login(user:String,password:String):AccountRefdetails(ref:AccountRef):AccounDetailscreatePortfolio(ref:AccountRef):void

SessionBean

AccountRef AccountDetails

AccountControllerlogin(user:String,password:String):AccountRefdetails(ref:AccountRef):AccounDetailscreatePortfolio(ref:AccountRef):void

control

view model

<<delegates>>

<<creates>> <<manages>>

An Example…An Example…

35©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Caller

getDetails

login

getAccountById

getId

getCashBalance

getPassword

findAccountByUserId

getDetails

login

AccountControllerBean AccountController Account

AccountRef

AccountDetails

36©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Roles & ResponsibilitiesRoles & Responsibilitiesn J2EE + light-weight object persistence allows the

Domain model to be separated from the Component modeln Domain model is implemented as Java objectsn J2EE manages the Component modeluComponents manipulate the domain model as Java objectslComponents are stateless SessionBeans

37©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

How(EIS Integration)

38©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Enterprise CoordinationEnterprise Coordination

n Coordination of “Application Data” with Enterprise Information Systems (EIS)

n Different approaches depending on needsu Synchronousl Distributed Transaction Management (XA)

u Asynchronousl Omni or bi-directional

n Connectivityu Point-to-pointl JDBC/JCA

uMessage-orientedl JMS

39©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Synchronous CoordinationSynchronous Coordination

n J2EE provides a Java Transaction ServiceuDistributed Transaction Manager

n Use J2EE architecture to build applicationu “Application Data” managed in the middle-tieru EIS connectivity via JDBC/CMP/JCA/JMS

n Transform objects to/from EIS representation as requiredu Tables/XML/…u Cache EIS data as “Application Data” for long running transactions

n Synchronization controlled by J2EEu Just need to call appropriate EJBs

n Message-driven Beans facilitate near-synchronous coordination

40©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

J2EE

AccountSessionBean

TradeSessionBean

SynchronousSynchronous

Sequence of events:(1) AccountSessionBean

updates Account(2) AccountSessionBean calls

TradeSessionBean to execute a trade

(3) TradeSessionBeanexecutes trade

(4) J2EE commits transaction

ObjectRepository

TradeExecution

Engine

(2)

coordinated

(4)

(3)

(1)

41©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

ConsiderationsConsiderations

Prosn Guaranteed consistency

Consn Expensiven Prone to unavailability of

external systemsu Unless using JMS

n Prone to performance bottlenecks of external systems

42©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

J2EE

AccountSessionBean

TradeSessionBean

Using MessageUsing Message--driven Beansdriven Beans

Sequence of events:(1) AccountSessionBean

updates Account(2) AccountSessionBean

sends message toTradeSessionBean

(3) TradeSessionBean reads message

(4) TradeSessionBeanexecutes trade

ObjectRepository

TradeExecution

Engine

(1)

(3)

(2)

(4)

Queue

coordinated

coordinated

43©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

ConsiderationsConsiderations

Prosn De-couples middle-tier

from enterprise systems

Consn Not synchronousn Additional complexity

44©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Asynchronous CoordinationAsynchronous Coordination

n Middle-tier persistence guarantees long term storageu It’s a database!

n Use J2EE architecture to build applicationu “Application Data” managed in middle-tier

n Periodically propagate “business transactions” from middle-tier to enterprise systems and vice-versau Time-based; # of transactions; …

n Omni-directionalu From or to the middle-tier

n Bi-directional

45©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Propagating changes from MiddlePropagating changes from Middle--tiertier

n Within J2EEu External event triggers EJB to perform synchronizationl EIS connectivity via JDBC/CMP/JCA/JMS

u Transform objects to EIS representationl Tables/XML/flat-files

n Outside J2EEu Batch processingl External application periodically exports changes from middle-tier to

appropriate EIS representation

n Suitable for propagating new “data”u No conflicts, “data” owner by middle-tier

46©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Within J2EEWithin J2EE

Sequence of events:(1) AccountSessionBean

updates Accounts(2) An external trigger calls

TradeSessionBean(3) TradeSessionBean gets

trades from middle-tier(4) TradeSessionBean

executes batch of trades

J2EE

AccountSessionBean

TradeSessionBean

ObjectRepository

TradeExecution

Engine

(1)

(4)

(2)

(3)

47©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Outside J2EEOutside J2EE

Sequence of events:(1) AccountSessionBean

updates Account(2) External application reads

updates(3) External application

executes batch of trades

J2EE

AccountSessionBeanObject

Repository

TradeExecution

Engine

(1)

(3)

(2)

ExternalApplication

48©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Propagating changes to the MiddlePropagating changes to the Middle--tiertier

n Within J2EEu External event triggers EJB to perform synchronizationl EIS connectivity via JDBC/CMP/JCA/JMS

u Transform EIS data to appropriate object representation

n Outside J2EEu Batch processingl External application periodically exports changes from EIS to

appropriate object representation

n Suitable for propagating new “data” or changes to reference datau No conflicts, “data” owned by Enterprise

49©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Within J2EEWithin J2EE

Sequence of events:(1) External system sends

message toInstrumentSessionBean

(2) InstrumentSessionBeanreads message

(3) InstrumentSessionBeancreates new instrument in the middle-tier

J2EE

InstrumentSessionBeanObject

Repository

TradeExecution

Engine

(3)

(1)

(2) ExternalApplication

50©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Outside J2EEOutside J2EE

Sequence of events:(1) External application reads

changes from external system

(2) External application creates new instruments in the middle-tier

(3) InstrumentSessionBeancan read new instruments

J2EE

ObjectRepository

TradeExecution

Engine

(3)

(1)

(2)

ExternalApplication

InstrumentSessionBean

51©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

ConsiderationsConsiderations

Prosn Decouples middle-tier

from enterprise systemsn Possible to coordinate with

batch-oriented systems

Consn Not synchronousn Not bi-directional

52©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

BiBi--directional Coordinationdirectional Coordination

n Replication of changes to/from middle-tieruData changed both in the middle-tier and enterprise

system

n Introduces potential for conflicting updatesuBest approach is to avoid need for bi-directional updates

53©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

SummarySummary

n Domain model-centric approach is good for process-centric applicationsuKeep object management orthogonal to the component

modelingn Domain model can easily support many use-cases

and applicationsn Software layering simplifies development and

reduces software dependenciesn Utilize J2EE capabilities for EIS Integration

54©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Interesting Design PatternsInteresting Design Patterns

Sun Java Center J2EE Patternshttp://developer.java.sun.com/developer/restricted/patterns/J2EEPatternsAtAGlance.html

n Session Façaden Value Objectn Data Access Objectn Value Object AssemblerMartin Fowler’s Information System Architecturehttp://martinfowler.com/eaaCatalog/

n Domain Modeln Data Transfer Objectn Remote Façade

55©2003 Versant Corporation

All products are trademarks or registered trademarks of their respective companies in the United States and other countries. The information contained in this document is property of Versant Corporation.

Thank you

top related