Domain Logic Patterns  Transaction Script  Domain Model  Table Module  Service Layer.

Slides:



Advertisements
Similar presentations
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Advertisements

And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Computer Monitoring System for EE Faculty By Yaroslav Ross And Denis Zakrevsky Supervisor: Viktor Kulikov.
Copyright W. Howden1 Lecture 7: Functional and OO Design Descriptions.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 5: Restaurant.
Layered Architectures The objectives of this chapter are: To understand the principles and importance of Layered Architectures To explain the structure.
Component-Level Design
From Class Diagrams to Databases. So far we have considered “objects” Objects have attributes Objects have operations Attributes are the things you record.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
SOS OOP Fall 2001 Object Oriented Programming in Java Week 1 Read a design Design a small program Extract a design Run a VAJ program Change that program,
IEG3080 Tutorial 11 Prepared by Ryan. Outline Enterprise Application Architecture Layering Structure Domain Logic C# Attribute Aspect Oriented Programming.
Spring 2009Computer Science Department, TUC-N Object Oriented Methods Architectural Patterns 2.
Unit Testing Tips and Tricks: Database Interaction Louis Thomas.
UNIT-V The MVC architecture and Struts Framework.
Data Access Patterns. Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
Object-Oriented Design. From Analysis to Design Analysis Artifacts –Essential use cases What are the problem domain processes? –Conceptual Model What.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Design I: Web Application Architecture and Patterns Peter Dolog dolog [at] cs [dot] aau [dot] dk Intelligent Web and Information Systems September.
JDBC Session 5 Tonight: Data Access Patterns 1.J2EE Architecture & Design Patterns 2.The Data Access Tier 3.Data Access Patterns –DataAccessObject (DAO)
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
What is Architecture  Architecture is a subjective thing, a shared understanding of a system’s design by the expert developers on a project  In the.
1 CMPT 275 Software Engineering Requirements Analysis Phase Requirements Analysis Activity (Identifying Objects, Scenarios) Janice Regan,
Java Classes Using Java Classes Introduction to UML.
ABC Insurance Co. Paul Barry Steve Randolph Jing Zhou CSC8490 Database Systems & File Management Dr. Goelman Villanova University August 2, 2004.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
1 Another group of Patterns Architectural Patterns.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Pemrograman Web MVC Programming and Design Pattern in PHP 5.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Object-to-Relational Mapping: The Crossing Chasms Pattern and Implementation Considerations Use of Meta Data in the Java Persistence Layer Presented by.
Architectural Patterns Support Lecture. Software Architecture l Architecture is OVERLOADED System architecture Application architecture l Architecture.
Domain and Persistence Patterns. Fundamental Pattern Types Design Patterns Business Logic Patterns.
3-Tier Client/Server Internet Example. TIER 1 - User interface and navigation Labeled Tier 1 in the following graphic, this layer comprises the entire.
Domain Driven Web Development With WebJinn Sergei Kojarski College of Computer & Information Science Northeastern University joint work with David H. Lorenz.
What to remember from Chap 13 (Logical architecture)
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
Domain Model—Part 2: Attributes.  A logical data value of an object  (Text, p. 158)  In a domain model, attributes and their data types should be simple,
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
Data Source Patterns.  Table Data Gateway  Row Data Gateway  Active Record  Data Mapper  Unit of Work  Identity Map.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
How I spend my money Software architecture course Mohan, Maxim.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Elaboration Iteration 3 – Part 3 - Persistence Framework -
SEA Side – Extreme Programming 1 SEA Side Software Engineering Annotations Architectural Patterns Professor Sara Stoecklin Director of Software Engineering-
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
Gerhard Dueck -- CS3013Analysis 1. Gerhard Dueck -- CS3013Analysis 2 Why analysis?  Yield a more precise specification of the requirements.  Introduce.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 6: Restaurant.
Observer Pattern Context:
MVC Architecture, Symfony Framework for PHP Web Apps
SOFTWARE DESIGN AND ARCHITECTURE
Server Concepts Dr. Charles W. Kann.
Architectural Patterns for Interactive Software
Datamining : Refers to extracting or mining knowledge from large amounts of data Applications : Market Analysis Fraud Detection Customer Retention Production.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Enterprise application architecture
Enterprise Architecture Patterns
Web Application Architectures
Web Application Architectures
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
JDBC Example.
Use Case Analysis – continued
Software Design Lecture : 39.
Web Application Architectures
Software Architecture & Design
Software Design Lecture 5.
Presentation transcript:

Domain Logic Patterns  Transaction Script  Domain Model  Table Module  Service Layer

Transaction Script  Organizes business logic by procedures where each procedure handles a single request form the presentation

TS: How It Works  Each business transaction corresponds to one transaction script  Business transaction: Book a hotel room  Tasks: check room availability, calculate rates, update the database – all handled in one BookARoom script.  Transaction scripts access the database directly  Don’t call any logic in the presentation layer  Organization  Each script is a procedure  Related scripts are enclosed in one class  Each script is in one class.

TS: Architecture TransactionScript businessTransaction1() businessTransaction2() businessTransaction3() Gateway findDataForBusinessTransaction1(sql_query) insertRecordsForBusinessTransaction1(sql_insert, items) updateRecordsForBusinessTransaction2(sql_update, items) … sql_query= “ SELECT * FROM table 1…” sql_insert = “INSERT into tablei…” sql_update = “ UPDATE tablei …” sql_delete = “DELETE FROM …” DB

TS: When to use it  When the domain logic is very simple  When transactions do not have a lot of overlap in functionality

Example Revenue Recognition  A contract is signed for one product  The revenue of a contract may not be recognized right away.  Different types of product may have different revenue recognition schedule  Three types of product  Word Processor: revenue recognized right away  Spreadsheet: 1/3 today, 1/3 in 60 days, 1/3 in 90 days.  Database: 1/3 today, 1/3 in 30 days, 1/3 in 60 days. Product Name type Contract date _signed revenue RevenueRecognition Amount date 1 1 * *

TS: Example RecognitionService calcRecognitions(contract#) recognizedRevenue(contract#, date) createContract(id, revenue, prod_id, date) … DatabaseGateway findContract(contract#) findRecognitionsFor(contract#, date) insertRecognition(contract#, revenue, date) … Sql_findContract = “ SELECT * FROM Contract WHERE id = ?” Sql_findRecogns = “select* from recog Where cid=? and date<?” Sql_insertContract = “INSERT into contract…” DB

createContract() Sequence Diagram: test cases :RecognitionService:DatabaseGateway :Tester insertContract() INSERT into contract … :Database calcRecognitions() insertRecognition() INSERT iinto Recog… recognizedRevenue() findRecognitionsFor() SELECT * FROM … insertRecognition() INSERT iinto Recog… insertRecognition()

TS: Example class Gateway { static String findRecogns = “SELECT * FROM revenueRecognition WHERE contract = ? And date <= ?”; static String findContract = “SELECT * FROM contract c, product p WHERE c.id = ? And c.pid = p.id”; public ResultSet findRecognitionsFor(int contrno, Date d) { PreparedStatement s = db.prepareStatement(findRecongs); s.setInt(1, contrno); s.setDate(2, d); ResultSet result = s.executeQuery(); return result; } public ResultSet findContract(int contrno) { PreparedStatement s = db.prepareStatement(findContract); s.setInt(1, contrno); ResultSet result = s.executeQuery(); return result; }

TS: Example class RecognitionService { private Gateway gw = new Gateway(); public Money recognizedRevenue(int contrno, Date d) { Money Result = Money.dollar(0); ResultSet rs = gw.findRecognitionsFor(contrno, d); while (rs.next()) { result = result.add(rs.getBigDecimal(“amount”)); } return result; } public void calculateRevenueRecognitions(int contrno) { ResultSet contrs = gw.findContract(contrno); totalRevenue = contrs.getBigDecimal(“revenue”); dates = contrs.getDate(“date_signed”); type = contrs.getChar(“type”); if (type == ‘S’) { db.insertRecognition(contrno, totalRevenue/3, date); db.insertRecognition(contrno, totalRevenue/3, date+60); db.insertRecognition(contrno, totalRevenue/3, date+90); } else if (type = ‘W’) { db.insertRecognition(contrno, totalRevenue, date); } else if (type == ‘D’ {... }...

Domain Model  An object model of the domain that incorporates both behavior and data

DM: Revenue Recognition Product Name type Contract date _signed revenue RevenueRecognition Amount date 1 1 * * recognizedRevenue(date) calculateRecognitions() calcRecognitions(contrct) RecognitionStrategy Complete RecognitionStrategy * 1 Three-way RecognitionStrategy calcRecognitions(contrct) isRecognizableBy(date) DB

DM: Example class RevenueRecognition { private Money amount; private Date date; public RevenueRecognition(Money amnt, Date d) {...} public Money getAmount() { return amount; } public boolean isRecognizableBy(Date date) { return this.date.before(date) || this.date.equals(date); }... } class Contract { private List revenueRecognitions = new ArrayList(); public Money recognizedRevenue(Date date) { Money result = Money.dollar(0); Iterator it = revenueRecognitions.iterator(); while (it.hasNext()} { RevenueRecognition r = (RevenueRecognition)it.next(); if (r.isRecognizableBy(date)) result = result.add(r.getAmount()); } return result; }...

DM: Example class RevenueRecognition { private Money amount; private Date date; public RevenueRecognition(Money amnt, Date d) {...} public Money getAmount() { return amount; } public boolean isRecognizableBy(Date date) { return this.date.before(date) || this.date.equals(date); }... } class Contract { private List revenueRecognitions = new ArrayList(); public Money recognizedRevenue(Date date) { Money result = Money.dollar(0); Iterator it = revenueRecognitions.iterator(); while (it.hasNext()} { RevenueRecognition r = (RevenueRecognition)it.next(); if (r.isRecognizableBy(date)) result = result.add(r.getAmount()); } return result; }...

DM: Example class Contract { private Product product; private Money amount; private Date dateSigned; private long id; public Contract(Product p, Money amnt, Date d) {...} public void addRecognition(RevenueRecognition rr) { revenueRecognitions.add(rr); } public Date getDateSigned() { return dateSigned; } public void calcRecognitions() { product.calcRecognitions(this); }... } interface RecognitionStrategy { public void calcRevenueRecognitions(Contract c); }

DM: Example class CompleteRecognitionStrategy implements... { public void calcRevenueRecognitions(Contract c) { c.addRecognition(new RevenueRecognition( c.getAmount(), c.getDateSigned()); } class ThreeWayRecognitionStrategy implements... { private int firstRecognitionOffset; private int secondRecognitionOffset; public ThreeWayRecognitionStrategy(int offset1, int offset2) { this.firstRecognitionOffset = offset1; this.secondRecognitionOffset = offset2; } public void calcRevenueRecognitions(Contract c) { c.addRecognition(new RevenueRecognition( c.getAmount()/3, c.getDateSigned()); c.addRecognition(new RevenueRecognition( c.getAmount()/3, c.getDateSigned()+offset1); c.addRecognition(new RevenueRecognition( c.getAmount()/3, c.getDateSigned()+offset2); }... }

DM: Example class Product { private String name; private RecognitionStrategy recogStrategy; public Product(String name, RecognitionStrategy rs) { this.name = name; this.recogStrategy = rs; } public void calcRecognitions(Contract c) { recogStrategy.calcRecognitions(c); } public static Product newWordProcessor(String name) { return new Product(name, new CompleteRecognitionStrategy()); } public static Product newSpreadsheet(String name) { return new Product(name, new ThreeWayRecognitionStrategy(60, 90)); } public static Product newDatabase(String name) { return new Product(name, new ThreeWayRecognitionStrategy(30, 60)); }

DM: Example class Tester { public static void main(String[] args) { Product word = Product.newWordProcessor(“IntelWord”); Product calc = Product.newSpreadsheet(“calc II”); Product db = Product.newDatabse(“DB IV”); Date today = System.today(); Contract c1 = new Contract(word, , today); c1.calcRecognitions(); Contract c2 = new Contract(calc, 24000, today); c2.calcRecognitions(); // sequence diagram – next slide Contract c3 = new Contract(db, , today); c3.calcRecognitions(); System.out.println(c1.recognizedRevenue(today + 10)); System.out.println(c2.recognizedRevenue(today + 70)); System.out.println(c3.recognizedRevenue(today + 80)); }

product:Product c2.:Contract calcRecognitions() calcRecognitions(c2) DM: Sequence Diagram: c2.calcRecognitions() rr1:RevenueRecognition recogStrategy:RecognitionStrategy (amount/3, date) calcRecognitions(c2) Mount = getAmount() date = getDateSigned() addRecognition(rr1) rr2:RevenueRecognition rr3:RevenueRecognition addRecognition(rr2) addRecognition(rr3) (amount/3, date + 60) (amount/3, date + 90) :Tester

c2.:Contract recognizedRevenue(date) isRecognizableBy(date) DM: Sequence Diagram: c2.recognizedRevenue() rr[0]:RevenueRecognitionrr[1]:RevenueRecognitionrr[2]:RevenueRecognition :Tester getAmount() isRecognizableBy(date) getAmount() isRecognizableBy(date) return result

Table Module  A single instance that handles the business logic for all rows in a database table or view  Each module is responsible for all the CRUD operations on the corresponding table.  No other modules are supposed to CRUD directly on the table  Each module also includes business logic that is tightly related to the table.

TM: Architecture Table_1 TableModule_1 CRUD operations on Table_1 Business Logic related to Table_1 Attributes Table_2 TableModule_2 CRUD operations on Table_2 Business Logic related to Table_2 Attributes Table_n TableModule_n CRUD operations on Table_n Business Logic related to Table_n Attributes Database

TM: Example - Tables Product Contract RevenueRecognition Id: Number dateSigned: Date revenue: Number prod_id: Number (FK) Id:Number name: String type: String Id: Number amount: Number date: Date c_id: Number (FK)

TM: Example - Modules Product ContractRevenueRecognition Insert(cid, revenue, prod_id, date) calculateRecognitions(c_id) getProductType(prod_id) Insert(c_id, amount, date) recognizedRevenue(c_id, date) DB

:Product :Contract getContract(id) getProductID() TM: Sequence Diagram: calcRecognitions() :RevenueRecognition :Tester contract:ResultSet getProductType(pid) calcRecognitions(cid) insert(cid, revenue/3, date) insert(cid, revenue/3, date+60) insert(cid, revenue/3 date+90) getRevenue() getDateSigned() return result DB SELECT INSERT

recognizedRevenue(c_id, date) getAmount() TM: Sequence Diagram: recognizedRevenue() :RevenueRecognition:Tester recognitions:ResultSet :Contract getRecognitions(c_id, date) getAmount() return result DB SELECT

Service Layer  Defines an application’s boundary with a layer of services that establishes a set of available operations and coordinates the application’s response in each operation.  Two type of business logic  Domain logic: pure logic of the business domain  E.g., calculating revenue recognitions of a contract  Application logic: application responsibilities  E.g., notifying administrators and integrated applications, of revenue recognition calculations

TM: Example - Modules Domain Model Service Layer Data Loader DB User Interfaces Integration Gateways

SL: Architecture  Domain logic: Domain model layer  Application logic: Service layer  Service layer:  Operation Scripts – A set of classes that implement application logic but delegate to domain model classes for domain logic.  Clients interact with the operation scripts  Operation scripts for a subject area are encapsulated in a class named SubjectService.

SL: Services and Operations  Determined by the needs of clients  Derived from use case models  Data validation  CRUD operations on domain objects  Notification of people or other integrated applications  All responses must be coordinated and transacted automatically by the service layer

SL: When to Use It  When there are many different kinds of clients  When the response may involve application logic that needs to be transacted across multiple transactional resources

SL: Example  Revenue Recognition  New requirements: once revenue recognitions are calculated, it must  a notification to contract administrators  Publish a message to notify other integrated applications

SL: Example RecognitionService calcRevenueRecogs(contr#) recognizedRevenue(contr#, date) ApplicationService Gateway send (toAddr, subj, body) get Gateway(): Gateway getIntegrationGateway(): IntegrationGateway IntegrationGateway publishRevenueRecogs(contract) ContractProductRevenueRecognition Domain Model

SL: Example class RecognitionService extends ApplicationService { public void calcRevenueRecogs(contractNo) { Transaction trans = Transaction.getNewTransaction(); trans.begin(); // delegate to domain objects Contract contract = Contract.getContract(contractNo); contract.calcRecognitions(); Contract c2 = new Contract(calc, 24000, today); // interact with transactional sources get Gateway().send (contract.getAdmin (), “RE: contract revenue recognitions”, contract.getId() +”Recognitions calculated”); getIntegrationGateway().publishRevenueRecogs(contract); trans.commit(); }

Domain Logic: Summary  Transaction Script  One script per user request/action  Good for simple, no-overlapping business logic  Domain Model  A set of interrelated objects for business logic  Good for application with complex business logic  Table Module  A module for the CRUD operations and business logic for a table in DB  Compromise between Transaction Script and Domain Model  Service Layer  Application logic is separated into a new layer from domain logic  Good for applications that have complex application logic – interacting with multiple transactional resources