Domain Logic Patterns - PowerPoint PPT Presentation

1 / 49
About This Presentation
Title:

Domain Logic Patterns

Description:

Abstract Class RecoginitionStrategy. abstract void calculateRevenueRecognitions (Contract contract) ... Table Module - Example ... – PowerPoint PPT presentation

Number of Views:125
Avg rating:3.0/5.0
Slides: 50
Provided by: ise66
Category:

less

Transcript and Presenter's Notes

Title: Domain Logic Patterns


1
Domain Logic Patterns
Class Fowler
  • ??? ???? ??????...

???? ?? 031996275 ???? ???? 032185035
2
Three Primary Layers
  • Presentation
  • Interacts with the user of the application
  • eg rich client, HTML browser, web service
  • Domain
  • Business rules, validations, calculations
  • Data Source
  • Connects to the rest of the enterprise
    environment
  • Persistence RDBMs
  • Messaging, TP monitors, legacy apps.

3
Domain ??????
4
???????? ?? ???????? ?????
  • ?????? ????? ??????
  • ???? ??
  • ???????? ????? ???????? ???? ????????? ????
    ??????????
  • ?????? ???????? ?????
  • ???????? ????? ??????

5
????? ?????
  • Transaction Script
  • Domain Model
  • Table Module
  • Service Layer

6
Transaction Script
  • ????? ?? ??????? ?????? ?"? ????????? ???? ??
    ???????? ????? ????? ?????? ????? ?????.
  • ??????? ????? ???? ???? ?????????.
  • ???? ???? ???? ?????? ??? ?? ????? ????? ???? ??
    ?????.
  • ??????? ????? ???? ????? ?????.
  • ????? ?????? ???? ?????????? ?? ?????? ?????
    ?????.

7
Transaction Script
  • ???????
  • ???? ?????
  • ??? ???? ??? ?????????
  • ?? ??????? ??????? ?? ???? ????
  • ???????
  • ???? ??????? ?????? ??? ????? ??? ??? ???????
  • ?? ????? ??????? ??? ??????

8
????? ????? ????? ??????
  • ?????? ????? ?? ????? ?????? ???? ????? ???
    ?????? ?????? ??"? ?????????? ????? (??????
    ??...)
  • ????? 3 ??????
  • Word Processor WP
  • ?? ????? ???? ???? ?????
  • Spread Sheet SS
  • 1/3 ???? ???? ????? 1/3 ???? 60 ??? ?- 1/3 ????
    90 ???
  • Database DB
  • 1/3 ???? ???? ????? 1/3 ???? 30 ??? ?- 1/3 ????
    60 ???

9
???? ??????
10
????? ????? ?????? Transaction Script
  • ???? 2 ?????? ??????? ????? Transaction Script
  • ????? ???? ????? ????? ??????? ??"? ??????
  • calculateRevenueRecognitions(contractID)
  • ????? ????? ????? ???? ?????? ?? ?????? ?????.
  • RecognizedRevenue(contractID,date)

11
Transaction Script
12
????? Transaction Script
  • ????? ??????? ?????? ????? ???????????.
  • ????? ?????????? ????? ?????? ????? ?????.
  • ???? ????? ??????
  • ?????? ???? ????????? ???? ??????? ??????

13
Domain Model
  • ???? ?????? ?? ??????? ?????
  • ??????? ????? ??????? ?????????? ??????? ??????.
  • ?? ??????? ????? ???? ?? ???? ??????
  • ???? ?????
  • ???? ?????
  • ???? ?????? ???? ?? ?????????? ??????? ?????????
    ????

14
Domain Model
  • ???????
  • ????? ??????? ?? ?????? ????? ??????
  • ????? ?? ??????? ?????????? (?????? ???????)
    ????? ?????
  • ????? ???? ??????? (????? ?? ???????)
  • scalability
  • ???????
  • ????? ???????? ??????? ???? ????? ???? ??????
    ????? ?? ?? ?-instances ???????
  • ???? ?????? ???????? ??????
  • ????? ??????? ????? ??????? ???? ????? ?????
    ?????

15
????? ????? ?????? Domain Module
  • ???? 2 ?????? ??????? ????? Domain Module
  • ????? ???? ????? ????? ??????? ??"? ??????
  • contract.calculateRecognitions ()
  • ????? ????? ????? ???? ?????? ?? ?????? ?????
  • Contract.recognizedReveneu (date)

16
Domain Model class diagram
17
Domain Model Sequence
18
Class RevenueRecognition.
  • private Money amount
  • private MfDate date
  • public RevenueRecognition(Money amount, MfDate
    date)
  • this.amountamount
  • this.datedate
  • public Money getAmount() return amount
  • Public boolean isRecognizableBy (MdDate asOf)
  • return asOf.after(date) asOf.equals(date)

19
Strategy classes
  • Abstract Class RecoginitionStrategy
  • abstract void calculateRevenueRecognitions
    (Contract contract)

20
class CompleteRecoginitionStrategy
  • public void calculateRevenueRecognitions
    (Contract contract)
  • contract.addRevenueRecognition (new
    RevenueRecognition(contract.getRevenue() contrac
    t.getWhenSigned()))

21
class ThreeWayRecoginitionStrategy
  • private int firstRecognitionOffset
  • private int secondRecognitionOffset
  • public ThreeWayRecoginitionStategy (int
    firstRecognitionOffset,
  • int secondRecognitionOffset)
  • this.firstRecognitionOffset
    firstRecognitionOffset
  • this.secondRecognitionOffset
    secondRecognitionOffset

22
class ThreeWayRecoginitionStrategy ..cont
  • void calculateRevenueRecognitions (Contract
    contract)
  • Money allocation contract.getRevenue().alloca
    te(3)
  • contract.addRevenueRecognition (new
    RevenueRecognition(allocation0,
  • contract.getWhenSigned()))
  • contract.addRevenueRecognition (new
    RevenueRecognition(allocation0,
  • contract.getWhenSigned().addDays(firstRecogniti
    onOffset)))
  • contract.addRevenueRecognition (new
    RevenueRecognition(allocation0,
  • contract.getWhenSigned().addDays(secondRecognit
    ionOffset)))

23
class Product
  • private String name
  • private RecognitionStrategy recognitionStrategy
  • public Product(String name, RecognitionStrategy
    recognitionStrategy)
  • this.name name
  • this.recognitionStrategy recognitionStrategy
  • public static Product newWordProcessor (String
    name)
  • return new Product(name, new CompleteRecognitionS
    trategy())

24
class Productcont
  • public static Product newSpreadsheet (String
    name)
  • return new Product(name, new ThreeWayRecognitionS
    trategy(60, 90))
  • public static Product newDatabase (String name)
  • return new Product(name, new ThreeWayRecognitionS
    trategy(30, 60))
  • Public void calculateRevenueRecognitions
    (Contract contract)
  • recognitionStrategy.calculateRevenueRecognition(c
    ontract)

25
Class Contract
  • private Product product
  • private Money revenue
  • private MfDate whenSigned
  • private Long id
  • private List revenueRecognitions new
    ArrayList()
  • public addRevenueRecognition (RevenueRecognition
    rr)
  • revenueRecognitions.add(rr)

26
class Contractcont
  • public Contract (Product product, Money revenue,
    MfDate whenSigned)
  • this.product product
  • this.revenue revenue
  • this.whenSigned whenSigned
  • public void calculateRecognitions ()
  • product.calculateRevenueRecognitions(this)

27
class Contractcont
  • public Money recognizedReveneu (MfDate asOf)
  • Money result Money.dollars(0)
  • Itrator it revenueRecognitions.itrator()
  • While (it.hasNext())
  • RevenueRecognition r (RevenueRecognition)
    it.next()
  • if (r.isRecognizableBy(asOf))
  • result result.add(r.getAmount())
  • return result

28
Domain Model Sequence
29
????? ???????? ????
  • class DelayedRecoginitionStrategy
  • private MfDate date
  • public void calculateRevenueRecognitions
    (Contract contract)
  • date contract.getWhenSigned()month.add(1)
  • contract.addRevenueRecognition (new
    RevenueRecognition(contract.getRevenue()
    ,date))

30
????? Product ???
  • Class Product
  • public static Product newEditor (String name)
  • return new Product(name, new DelayedRecoginitionS
    trategy())

31
????? ???? ????? ????
  • public Product editorProduct. newEditor(word2000
    )
  • public Contract cnew
  • Contract (editor, amount, 21/3/75)

32
????? Domain Module
  • ??????? ????? ??????? ?????????? ??????? ??????.
  • ????? ??????? ?? ?????? ????? ??????
  • ????? ?? ??????? ?????????? (?????? ???????)
    ????? ?????
  • ????? ??????? ????? ??????? ???? ????? ????? ?????

33
Table Module
  • Instance ???? ????? ?? ??????? ????? ???? ?? ????
  • ???? ?? ???? ????? ????? ??? ?????? ???? Instance
    ????
  • ???? ?????? ?-Domain Module ???
  • ??? ???? ??????? Instance
  • ??????? ???? ???? ??? ???????

34
Table Module
  • ?? ????? ????? ???? ???? ???? ?? ??? ????? ?????
    ?????
  • ?? ???? OO ??????? ??? ?????? ?-.net ??????
  • ?? ?????? ????? ?? ???? ??????? ????? ???? ??-
    Domain Module ?? ???? ???? ????? ???? ???????.

35
Table Module
  • ???????
  • ??? ?? ?????? ? DB.
  • ???? ??? ?????? ??????? PLSQL??? ???? ??????
    ???????.
  • ????? ????? ?? ???? ?????? ???????? ????? ????,
    ???? VB ???????? ??? ?? ?????? RS.

36
Table Module
  • ???????
  • ???? ???? ????? OO.
  • ??????????? ???? ???? ??? ????? ??.
  • ??? ???? ??????? ???????.
  • ???? ?? ????? ??????.
  • ???? ????? ????? ?? ???? ???????.

37
Table Module
38
Table Module Sequence
39
Table Module - Example
  • ????? ?????? ?? ????? ??????
  • ????? ????????? ?? Table Module
  • class Table Module
  • protected DataTable table
  • protected TableModule (DataSet ds, String
    tableName)
  • table ds.TablestableName

40
Table Module - Example
  • ????? ??? ????? ?constructor ?? ? superclass ??
    ?? ????? ??????
  • Class contract
  • public Contract (DataSet ds) base (ds,
    contracts)
  • ????? ????? Table module ??? ?????, ?"? ?????
    Data Set ? constractor.
  • Contract new contract (dataset)

41
Class Contract
  • ??????? ?????? ???? ??????? contract ??? ????
    ??? ??????? ??? ???? ? Domain Module - ???? ??
    ?????.
  • Public void CalculateRecognition (long
    contractID)
  • If (prod.GetProductType(prodID)
    productType.wp)
  • ..
  • else if (prod.GetProductType(prodID)
    productType.ss)

42
Table Module - Example
  • ????? ?? ??????? ???????? ?????? ?????, ?????
    ??????? ??????? RevenueRecognition ????? ?? ????
    ????? ??????.
  • ????? ? Domain Module, ?? ?????? ????? ????????
    Contract.

43
????? Table Module
  • ??????? ????? ???? ????????? ?????? ??????.
  • ???? ??????? ???? ?? ???? ???????
  • ????? ??????? ????? ??????? ???? ????
  • ???? ?????? OO ???????

44
???????? ?? ???????? ?????
  • ????? ???????
  • ?????? ????? ??????
  • ???? ??
  • ???????? ????? ???????? ???? ????????? ????
    ??????????
  • ?????? ???????? ?????
  • ???????? ????? ??????

45
Service Layer
  • ????? ???? ?? ? Business logic ???? ?????
  • Domain logic ???? ????? ???? ?????? ?? ?
    business ???? ????????? ?????? ??????.
  • Application logic ???? ??????? ?? ?????? ????
    ???? ????? ?????, ????????? ?? ?????? ????? ?????
    ????? ?????
  • ???? ???????? Application logic ???????Workflow
    ??????? ???? ?????? ??????

46
Service Layer
47
Service Layer
  • ?? ????? ?????? ? Application logic ??? ???????
    ?? Domain Model ? Table Module
  • ??????? ???? ?????? ?????? ???? ?? ?? ?????
    Application logic ?????
  • ????? ???? ??????? Service Layer ?????? ?? ????
    Domain Logic
  • ?"? ?? ????? ?????? ??????? ?? ?-Domain Logic ????

48
?????
49
?????
  • ????? 3 ????? ???? ?? ???? ??????? ??????
  • ???? ??????????? Transaction Script Module
  • ???? ?????? ????? Domain Module
  • ???? ??????? Table Module
  • ???????? ???????? ?????? ??? ??????
  • ??????? ???????
  • ?????? ?????? ??????
  • ????? ????? ?????? ?? ??????? ????? ???? ?????
    ????? ?-Service Layer
Write a Comment
User Comments (0)
About PowerShow.com