Continuous Integration 엔터프라이즈어플리케이션아키텍처 조영호카페PJT팀 2008.10.01 youngho.cho@nhncorp.com
목차 1. Domain Logic Pattern 2. Data Source Pattern 3. Putting It All Together
1. Domain Logic Pattern
Layered Architecture 3 레이어아키텍처 프리젠테이션 (Presentation) 사용자요청처리처리결과에따른뷰생성화면네비게이션처리도메인로직 (Domain Logic) 비즈니스로직처리어플리케이션플로우처리 Presentation Domain Logic Service Domain Model Presentation Domain Logic Transaction Script Anemic Domain Model 퍼시스턴스 (Persistence) DB 관련로직처리 Persistence Persistence 4 / 문서의제목
Transaction Script 작동원리 비즈니스로직을단일프로시저로구성프로시저는하나의트랜잭션을의미각트랜잭션은하나의트랜잭션스크립트로구성 EJB의기본아키텍처 사용시점 도메인로직이단순한경우적합 단점 코드중복 Anemic Domain Model 행위와데이터분리유지보수성저해 RecognitionSevice recognizedrevenue(contractid, asof) : Money caculaterevenuerecognitions(contractid) : void 5 / 문서의제목
Transaction Script 중앙집중식 (Centralized) 제어스타일 트랜잭션스크립트가대부분의중요사항결정 Anemic Domain Model 수반트랜잭션스크립트주변의오브젝트는 dumb object getter/setter 메소드만포함 Value Object, Data Transfer Object, Transfer Object a Recognition Service a Data Gateway caculaterecgontions(contractid) findcontract(contractid)) a contract result set get data *insert revenue recognition 6 / 문서의제목
Domain Model 작동원리 행위와데이터를통합하는도메인의객체모델 상호연결된객체들간의협동을통해비즈니스로직처리 사용시점 비즈니스로직이복잡한경우적합요구사항이계속변하는경우 Data Mapper를사용하는경우 DDD(Domain-Driven Design) [DDD] 단점 OO 분석 / 설계능력을보유한팀필요 Contract recognizedrevenue(date) calculaterecognitions() * 1 Product calculaterecognitions(contract) 1 RecognitionStrategy CompleteRecognition Strategy 7 / 문서의제목
Domain Model 위임식 (delegated), 분산식 (dispersed) 제어스타일 연관된오브젝트들에게책임을분산특정오브젝트가모든동작을제어하기보다는오브젝트들이상호협력및조율모든결정들은조그만책임들로축소 Real Object-Oriented a Contract a Product a Recognition Strategy caculaterecgontions caculaterecgontions(a Contract) caculaterecgontions(a Contract) * new a Revenue Recognition 8 / 문서의제목
Domain Model 예 영화예약시스템 Region 0..* Theater ShowingType 1 1 0..* 1 Seat 0..1 leftseat 0..* 0..1 rightseat ShowingRoom 1 0..* Showing getavailableadjacentseats() reserveseats() sellreservationseats() seatid 1 1 Movie SeatState isavailable() next() previous() 1 1 ReservationSeat isadjacent() isavailable() reserve() Sell() 0..* 0..1 Reservation caculatereservationprice() calculatepurchaseprice() Paid() AbstractSeatState 0..1 leftseat 0..1 rightseat 1 0..1 Purchase 0..1 nextseatstate 0..1 previousseatstate Occupied Reserved Sold 9 / 문서의제목
Service Layer 작동원리어플리케이션경계정의 비즈니스오퍼레이션집합을정의 트랜잭션제어 오퍼레이션의응답조정 어플리케이션비즈니스로직캡슐화 Transaction Script 패턴의경우 Transaction Script 자체가 Service Layer 의역할수행 구현방법 Domain Façade Domain Model 위의얇은 Façade 집합으로구현 Operation Script 일련의두꺼운클래스로구현 어플리케이션로직을직접구현하지만도메인로직은 Domain Model 로위임 자바구현 POJO Façade AOP 를사용한 POJO Session Façade EJB Sessio Bean 10 / 문서의제목
Layered Architecture Presentation Presentation Domain Logic Service Domain Logic Transaction Script Domain Model Anemic Domain Model Persistence Persistence Domain Model Transaction Script 11 / 문서의제목
2. Data Source Pattern
Table Data Gateway 작동원리데이터베이스테이블에대한 Geateway 역할을하는객체 하나의테이블데이터게이트웨이는단일테이블또는뷰에접속하는 SQL 처리 사용시점간단한도메인모델이나트랜잭션스크립트를사용하는경우 Person Gateway find(id) : RecordSet findwithlastname(string) : RecordSet update(id, lastname, firstname, numberofdependents) insert(lastname, firstname, numberofdependents) delete(id) 13 / 문서의제목
DAO(Data Access Object) 작동원리독립된레이어에데이터접근및조작에관련된로직을캡슐화 클라이언트에게단일한 API 를제공 자바인터페이스의추상화계층제공 사용시점비즈니스로직과영속성로직간의분리를원하는경우 비즈니스객체로부터서로다른데이터접근전략을감추려는경우 Business Object Business Object DAO DAO JdbcDAO EjbDao CmpEntity Bean CmpEntity Bean CmpEntity Bean 14 / 문서의제목
Data Mapper 작동원리객체와데이터베이스간의독립성을유지하면서객체와데이터베이스간에데이터이동 Impedance Mismatch 해결 메모리객체는데이터베이스의존재를인식하지않아도됨 ORM(Object-Relational Mapper) Domain Model 패턴기반의 POJO 개발을위한필수요소 사용시점데이터베이스스키마와객체모델이독립적으로발전하기를바라는경우 Domain Model 패턴적용시 비즈니스로직이복잡한경우 Data Mapper 를자체개발하지말것 Person lastname firstname numberofdependents getexemption isflaggedforaudit gettaxableearnings insert update delete PersonMapper 15 / 문서의제목
Repository 작동원리생명주기중간에 Entity 를 traverse 하기위한시작지점제공 Entity 컬렉션을관리 Entity 를검색하고삭제하기위한메소드정의 사용시점 Domain Model 패턴을사용하여 Domain Logic 을구성하는경우 Domain Logic Layer 내에서 Entity 에대한전역접근이필요한경우 Entity 에대한가상적인 in-memory 컬렉션을제공하려는경우 Repository 는 Domain Logic Layer 에포함 fortrackingid( t456 ) client t456 :TradeOrderRepository fortrackingid(string) : TradeOrder outstandingforbreakerageaccountid(string) : Collection locate/reconstitute t456:tradeorder trackingid = t456 brokerageaccountid = 123 type = BuyOrder security = WCOM numberofshares = 500 16 / 문서의제목
Lazy Loading 작동원리오브젝트가실제로사용될때데이터베이스로부터자동로드 불필요한경우로드시간절약 :Customer the database getorders() [ objects not loaded ] Customer * Order load orders orders 17 / 문서의제목
3. Putting It All Together
Transaction Script Based Architecture 기본패턴 Transaction Script 비즈니스로직제어중앙집중화 Table Data Gateway DAO 구현시테이블별로데이터접근로직구성 Anemic Domain Model getter/setter 메소드만을가지는데이터전송용객체 프레임웍구성 Spring Aspect-Oriented Programming Dependency Injection ibatis SQL Maps SQL Mapper DAO 내부구현 Table Data Gateway 구성 SQL 을 XML 로관리 Anemic Domain Model 과 SQL 결과값간의자동매핑 19 / 문서의제목
Transaction Script Based Architecture EJB Example <<session bean>> TransfrerService TrasactionDetails transfer(fromaccountid, toaccountid, amount) AccountDAO TrasactionDAO TransaferResultDTO AccountDTO Account(accountId) saveaccount(accountdto) AccountDTO Account(accountId) saveaccount(accountdto) AccountDTO accountid balance txnid date TransactionDetailsDTO 20 / 문서의제목
Transaction Script Based Architecture POJO Example Spring AOP Spring Dependency Injection RevenueRecognitionDAO Spring Transaction Interceptor RecognitionSevice recognizedrevenue(contractid:long, asof:data):money caculaterevenuerecognitions(contractid:long) : void -recognitiondao RecognitionSeviceImpl Anemic Domain Model ReveneuRecognition findrevenuerecognition(id:long) : RevenueRecognition saverevenuerecognition(recognition:revenuerecognition) : void getamount() : Money setamount(money:money) : void getdate() : Date setdate(date:data) : void SqlMapRevenueRecognitionDAO Table SQL Mapping XML Document Data Gateway 21 / 문서의제목
영화예약 Class Diagram ScheduleBO reserve(showingid:long, seats:long[],adultseatcount:int, teenagerseatcount:int) : Reservation ReservationDAO createreservation(reservatio) : Reservation ScheduleBOImpl ReservationSeatDAO updatereservationseatstate(reservationseat) : int getreservationseat(seatid:long, lock:boolean):reservationseat Reservation getid() : long setid(long) : void getshowingid() : long setshowingid(long) : void getadultseatcount() : int setadultseatcount(int) : void getteenagerseatcount() : int setteenagerseatcount() : int ReservationSeat getid() : long setid(long) : void getseatstate() : String setseatstate(string) : void 22 / 문서의제목
영화예약 Sequence Diagram reservation=r eserve(showingid, seatids, adultseatcount, teenagerseatcount) :TransactionScript reservation :Reservation :ReservationDAO :ReservationSeatDAO reservationseat :ReservationSeat <<create>> createreservation(reservation) reservationseat=getreservationseat(seatid, true) setstate( 02 ) reservationid=getreservationid() updatereservationid(reservationid) updatereservationseatstate() 23 / 문서의제목
Domain Model Based Architecture 기본패턴 Service Layer 어플리케이션경계정의트랜잭션제어 Domain Model 행위와데이터를함께가지는도메인객체들로구성객체들의협력을통해비즈니스로직처리 Data Mapper 도메인객체와데이터베이스간의매핑수행 ORM(Object-Relational Mapper) 사용 프레임웍구성 Spring Aspect-Oriented Programming Dependency Injection Hibernate Open-Source ORM Repository 내부구현 Data Mapper 구성투명한영속성 (Transparent Persistence) Metadata Mapping 24 / 문서의제목
Domain Model Based Architecture POJO Example Spring AOP Spring Transaction Interceptor TransferService BankingTransaction transfer(fromid, toid, amount) Spring Dependency Injection Domain Model TransferServiceImpl Banking Transaction Account debit(amount) credit(amount) AccountRepository findaccount(id) BankingTransactionRepository createtransaction(..) Data Mapper OverdraftPolicy Hibernate AccountRepository BankingTransaction Repository New OverdraftPolicy Limitted OverdraftPolicy Hibernate Object/relational mapping XML document 25 / 문서의제목
영화예약 Class Diagram ScheduleService reserve(showingid:long, seats:long[],adultseatcount:int, teenagerseatcount:int) : Reservation ShowingRepository -showingrepository ScheduleServiceImpl -reservationrepository ReservationRepository getshowingwithlock(showingid) :Showing savereservation(reservation) Showing seatid 1 SeatState 1 1 ReservationSeat 0..* 0..1 Reservation 0..1 leftseat 0..1 rightseat AbstractSeatState 0..1 nextseatstate 0..1 previousseatstate Occupied Reserved Sold 26 / 문서의제목
영화예약 Sequence Diagram reservation= reserve(showingid, seatids, adultseatcount, teenagerseatcount) :ScheduleService :Showing Repository showng :Showing seat :ReservationSeat Unoccupied State :Unoccupied reservedstat e :Reserved :Reservation Repository showing=getshowingwithlock(showingid) reservation=reserveseats(seatids, adultseatcount, teenagerseatcount) <<create>> reservation :Reservation calculatereservationprice( ) loop reserve(reservation) [for ReservationSeats in seatids] next(reservation) setstate( reservedstate) savereservation(reservation) 27 / 문서의제목
Thank you.
Question.