UML basics UML distilled, a brief guide to the standard Modeling language, by Martin Fowler, 2000.
Analysis Patterns - jaoo.orgjaoo.org/jaoo1999/schedule/MartinFowlerAnalysisPatterns.pdf1 Page 1 ©...
Transcript of Analysis Patterns - jaoo.orgjaoo.org/jaoo1999/schedule/MartinFowlerAnalysisPatterns.pdf1 Page 1 ©...
1
Page 1 © Martin Fowler 9/11/99
Analysis PatternsAnalysis Patterns
Martin FowlerMartin Fowler
fowlerfowler@@acmacm.org.orghttp://http://ourworldourworld..compuservecompuserve.com/homepages/Martin_Fowler.com/homepages/Martin_Fowler
Page 2 © Martin Fowler 9/11/99
What we will coverWhat we will cover
Introduction
ObservationPatterns
AccountingPatterns
How to usePatterns
2
Page 3 © Martin Fowler 9/11/99
PatternsPatterns
q “Gang of Four”: Design Patterns bookq Pattern Languages of Programming (PLoP)
conferences
…projects fail despite the latest technologyfor lack of ordinary solutions.
Ralph Johnson and Ward Cunningham
A pattern is an idea that has been useful in one practical contextand will probably be useful in others.
[Fowler]
http://www.hillside.net/patterns
Page 4 © Martin Fowler 9/11/99
Mediator Colleague
Concrete Mediator
Concrete Colleague
Concrete Colleague
Design Pattern: Design Pattern: MediatorMediator
q Define an objectthat encapsulateshow a set of objectsinteract.
Gamma, E., Helm, R., Johnson, R. and Vlissides, J. DesignPatterns: elements of reusable object-oriented software,Addison-Wesley, Reading, MA, 1995.
www.industriallogic.com/papers/learning.html
3
Page 5 © Martin Fowler 9/11/99
Analysis PatternsAnalysis Patternsq David Hay
â Relational data modelsâ Not connected with
patterns community, butstill patterns
â Hay, D. Data ModelPatterns: conventions ofthought, Dorset House,New York, NY, 1996.
q Martin Fowlerâ OO conceptual modelsâ Healthcare, Accounting,
Financial Trading, Planningâ Fowler, M. Analysis
Patterns: reusable objectmodels, Addison-Wesley,Reading MA, 1997.
Page 6 © Martin Fowler 9/11/99
NotationNotation
q Interface not implementation
Each orderhas a singlecustomer
Each customermay havemany orders
A customer may be acorporate customer or anindividual customer
An ordermay be apriority order
Customer
IndividualCustomer
CorporateCustomer
placedOn : Date
dispatch()
Order
[1
PriorityOrder
Martin Fowler with Kendall Scott, UML Distilled: Applying theStandard Object Modeling Language, Addison-Wesley 1997
4
Page 7 © Martin Fowler 9/11/99
Patterns in 3 tier architecturePatterns in 3 tier architecture
q Visibility is from application to domainq Domain carries shared servicesq Applications do not see databaseq Patterns used in domain tier
application1
application2
application3
domain database
Page 8 © Martin Fowler 9/11/99
Observation PatternsObservation Patterns
Introduction
ObservationPatterns
AccountingPatterns
How to usePatterns
5
Page 9 © Martin Fowler 9/11/99
Attributes of PersonAttributes of Person
What are the problems with this model?
height : Numberweight : Numberblood glucose level : Number
Person
Page 10 © Martin Fowler 9/11/99
QuantityQuantity
q Define arithmetic operations for quantityq Money is a kind of quantityq Use Conversion Ratio to convert to other
units
height : Quantityweight : Quantityblood glucose level : Quantity
Person
What if there are tens or hundreds of attributes?
+, -, *, /<, >, =, <=, >=as(Unit) : QuantitytoString() : StringvalueOf(String) : Quantity
amount: Numberunits: Unit
Quantity
6
Page 11 © Martin Fowler 9/11/99
MeasurementMeasurement
When should we use this model?
- Martin Fowler is six feet tall
q For each attribute of person, define aninstance of phenomenon type
q To record a value for a person create ameasurement
amountOf(PhenomenonType) : Quantity
Person
amount: Quantity
Measurement
Phenomenon Type
[
1
[
1
Page 12 © Martin Fowler 9/11/99
amountOf(PhenomenonType) : QuantityvalueOf(PhenomenonType) : Phenomenon
Person
amount: Quantity
Measurement
Phenomenon Type
[
1
[
1
Observation
CategoryObservation
Phenomenon
[
1
[
1
{overlapping}
ObservationObservation
- Martin Fowler is blood group O
- Martin Fowler is Male
7
Page 13 © Martin Fowler 9/11/99
Knowledge and Operational LevelsKnowledge and Operational Levels
q Operationalâ regular day to day objects
q Knowledgeâ Meta-Dataâ Objects that capture domain rules
Knowledge
Operational
PhenomenonAssociative
Function
arguments
[[
[ 1result
CategoryObservation
ObservationPerson
[1
[
1
Page 14 © Martin Fowler 9/11/99
RangeRange
- Between 10 miles and 50 miles
- 6m < x ≤≤ 15m
upper: Magnitudelower: MagnitudeisUpperInclusive: BooleanisLowerInclusive: Boolean
includes (Magnitude) : Booleanoverlaps (Range) : Booleanabuts (Range) : Boolean
Range
=<=<>>=
Magnitude
8
Page 15 © Martin Fowler 9/11/99
Phenomenon with RangePhenomenon with Range
- Normal Heart Rate is 60–80 beats per minute
Range Phenomenon
PhenomenonType
1
[
1
{phenomena's rangesshould not overlap}
Page 16 © Martin Fowler 9/11/99
Assigning a phenomenonAssigning a phenomenon
a Measurementheart rate:
Phenomenon Typenormal heart rate:
Phenomenonfast heart rate:Phenomenon
new
phenomenon = phenomenonIncluding(aMeasurement)
includes (aMeasurement)
false
includes (aMeasurement)
true
fastHeartRate
setPhenomenon(fastHeartRate)
9
Page 17 © Martin Fowler 9/11/99
Corporate Finance ProblemCorporate Finance Problem
q Each month we get a large number ofindicators (revenue, income, units sold…)
q Each indicator is given values for good,reasonable, poor, or badâ If revenue is over 105 million that is good,
over 95 is reasonable, over 90 is poor andunder 90 is bad.
q Indicators can be calculated based onother indicatorsâ Revenue = income - costsâ Income = units sold * average price
Page 18 © Martin Fowler 9/11/99
Measurement ProtocolMeasurement Protocol
q Source Protocols read from externalsystems
q Calculated Protocols are calculations
MeasurementProtocol
SourceMeasurement
Protocol
CalculatedMeasurement
Protocol
PhenomenonType
Measurement1[ 1[
{list}
10
Page 19 © Martin Fowler 9/11/99
Calculated MeasurementCalculated Measurement
q Calculated measurement protocol hasformula and arguments
- Revenue = Income - Costs
- Income = Number sold X Average Price
- Body Mass Index = weight / height2
MeasurementProtocol
CalculatedMeasurement
Protocol
PhenomenonType
1
[
Formula1
result type
argument types {list}
[
[
[
Page 20 © Martin Fowler 9/11/99
Creating a MeasurementCreating a Measurement
q Factory method for measurements
a MeasurementProtocol
a Formula
a Measurement
create Measurement
find arguments
execute
new
return quantity
11
Page 21 © Martin Fowler 9/11/99
Observation PatternsObservation Patterns
q Quantityq Measurementq Observationq Rangeq Phenomenon with Rangeq Measurement Protocol
Page 22 © Martin Fowler 9/11/99
Accounting PatternsAccounting Patterns
Introduction
ObservationPatterns
AccountingPatterns
How to usePatterns
12
Page 23 © Martin Fowler 9/11/99
AccountAccount
q Entries record history of changes to anaccount
Where might we use this model?
balance: Money
Accountamount: MoneywhenCharged: TimepointwhenBooked: Timepoint
Entry
1 [
{balance = sum(entries)}
Page 24 © Martin Fowler 9/11/99
TransactionTransaction
- I withdraw $100 from my checking account
- The Willenhall Coal Company delivers 30 tons of coal to BilstonGasworks
Why are transactions useful?
Account Transaction[1 12..[
amount: Money
Entry
{sum(entries.amount) = 0}
13
Page 25 © Martin Fowler 9/11/99
Posting Rule Posting Rule (simple)(simple)
- 5% of state tax is deducted from gross income
Account1
1trigger
outputmultiplier: Number
execute()
Posting Rule
Page 26 © Martin Fowler 9/11/99
Posting Rule Method1calculation
Account
1 1triggeroutput
Individual Instance MethodIndividual Instance Method
q Each instance of posting rule has its ownmethod
q Conceptual statement
- Income tax is deducted at
15% for first $31,500
28% to $80,750
31% to $130,800
…
14
Page 27 © Martin Fowler 9/11/99
Account TypesAccount Types
- Apply the graduated tax algorithm to the gross pay of Doug andDinsdale Piranha to yield their net pay.
Account Type Posting Rule
EmployeeAccount Employee
1
1[
[
output
trigger
1
Knowledge
Operational
[Method
1
Page 28 © Martin Fowler 9/11/99
Network of Posting RulesNetwork of Posting Rulesraw Overtime:Account Type
straight OT hours :Account Type
Excess Hours:Account Type
OT hours PR
Straight OT Payment: Posting Rule
Excess Payment:Posting Rule
Straight Dollars :Account Type
Excess Hours:Account Type
Premium Hours:Account Type
straight += inputif (Sunday) excess += inputelse excess += input * 0.5
3 hours (Tuesday)
3 hours 1.5 hours
out = input *employee.rate
$150
excess = input *employee.otRate * 2/3premium = input *employee.otRate * 1/3
$50 $25
Total Overtime :Summary Account
Type$225
15
Page 29 © Martin Fowler 9/11/99
Executing the networkExecuting the networka list of Posting Rules
pay (employee)
a Posting Rule
*[for all elements]run (employee)
an Employee
get account (input account type)
input Account
get unprocessed entries
* [for each entry]
execute posting rule
output Account
post entry
Page 30 © Martin Fowler 9/11/99
Procedural ApproachProcedural Approach
Process Hours
Dollarize StraightHours
Dollarize ExcessHours
H
H
Get straight hoursaccount
multiply by rate
post to straightdollars
get unprocessedentries
H
[for all entries][
16
Page 31 © Martin Fowler 9/11/99
Changing the RulesChanging the Rules
Process Hours
Dollarize StraightHours
Dollarize ExcessHours
H
H
Get straight hoursaccount
multiply by rate
post to straightdollars
get unprocessedentries
H
[for all entries][
[before April 15]
multiply by rate * 0.9
[on or after April 15]
Page 32 © Martin Fowler 9/11/99
Adding an Adding an effectivity effectivity timetime
Account Type
EmployeeAccount
Employee
1
1[
[
output
trigger
1
[Method
1effectivity: Date Range
Posting Rule
q Add a date range for each posting ruleinstance
17
Page 33 © Martin Fowler 9/11/99
New BehaviorNew Behaviora list of Posting Rules
pay (employee)
a Posting Rule
*[for all elements]run (employee)
an Employee
get account (input account type)
input Account
get unprocessed entries in (date range)
* [for each entry]
execute posting rule
output Account
post entry
Page 34 © Martin Fowler 9/11/99
Implementing with singletonImplementing with singleton
What are the strengths and weaknesses?
state: State
calculate()
State Tax PR
state: State
calculate()
CA Tax PR
{Singleton}
state: State
calculate()
MA Tax PR
{Singleton}
state: State
calculate()
NY Tax PR
{Singleton}
18
Page 35 © Martin Fowler 9/11/99
Strategy PatternStrategy Pattern
What are the strengths and weaknesses?
calculate()
Calculation Strategy
calculate()
CA Tax
{Singleton}
calculate()
MA Tax
{Singleton}
calculate()
NY Tax
{Singleton}
{abstract}
state: State
calculate()
State Tax PR1
«Method»return strategy.calculate()
Page 36 © Martin Fowler 9/11/99
Parameterized MethodParameterized Method
What are the strengths and weaknesses?
state: Staterate: Number
calculate()
State Tax PR
«Method»multiply by rate
19
Page 37 © Martin Fowler 9/11/99
Combining ImplementationsCombining Implementations
q Combination of singleton andparameterized approaches
rate: Number
calculate()
Multiplier PR
state: State
calculate()
State Tax PR
calculate()
CA Tax PR
{Singleton}
calculate()
NYTax PR
{Singleton}
Page 38 © Martin Fowler 9/11/99
Posting Rule ExecutionPosting Rule Executionq Eager firing
â Fire when entry added to accountâ Find all posting rules looking at that account
and fire them (etc, etc)
q Posting rule basedâ Have a coordinator which tells posting rules
when to fire
q Account based basedâ Have a coordinator tell which accounts when
to fire their outbound posting rules
q Backward Chainedâ When you ask an account for its balanceâ All input accounts must be asked for value
(etc, etc)
Which would you choose?
20
Page 39 © Martin Fowler 9/11/99
Accounting PatternsAccounting Patterns
q Accountq Transactionq Posting Ruleq Individual Instance Methodq Posting Rule Executionq Posting Rules for Many Accountsq Accounting Practice
Page 40 © Martin Fowler 9/11/99
How to use PatternsHow to use Patterns
Introduction
ObservationPatterns
AccountingPatterns
How to usePatterns
21
Page 41 © Martin Fowler 9/11/99
Using PatternsUsing Patternsq Starting point for development
â Inspiration to get things going
q Comparison for reviewâ Why are we different to this pattern?
q Documentation of complex frameworksâ Highlight the key patterns
q Informal standardizationq Mining from legacy systemsq Training
â The next step after basic training
The why is at least as important as the what
Page 42 © Martin Fowler 9/11/99
Learning about PatternsLearning about Patterns
q Read the booksâ Use a book groupâ Discuss two chapters a week over lunch
q Take a training courseâ Training must emphasize using patternsâ Instructors expertise is central
q Try using the patternsâ You cannot understand a pattern till you
have tried itâ Trying a pattern and finding it does not fit is
valuable
q Write some patterns
http://www.hillside.net/patterns
22
Page 43 © Martin Fowler 9/11/99
BooksBooksq Beck, K. Smalltalk Best Practice Patterns. Volume 1: Coding,
Prentice Hall, Englewood Cliffs, NJ, 1997.q Buschmann, F., Meunier, R., Rohnert, H., Sommerlad, P. and
Stal., M. Pattern-Oriented Software Architecture - A System ofPatterns, John Wiley, 1996.
q Coad, P., North, D. and Mayfield, M. Object Models: strategies,patterns and applications, Prentice Hall, Englewood Cliffs,1995.
q Coplien, J.O. and Schmidt, D.C. Pattern Languages of ProgramDesign, Addison-Wesley, Reading, MA, 1995.
q Gamma, E., Helm, R., Johnson, R. and Vlissides, J. DesignPatterns: elements of reusable object-oriented software,Addison-Wesley, Reading, MA, 1995.
q Fowler, M. Analysis Patterns, Addison-Wesley, Reading MA,1997
q Hay, D. Data Model Patterns: conventions of thought, DorsetHouse, New York, NY, 1996.
q Vlissides, J.M., Coplien, J.O. and Kerth, N.L. ed.PatternLanguages of Program Design 2, Addison-Wesley, 1996.
http://www.hillside.net/patterns
Page 44 © Martin Fowler 9/11/99
Final ThoughtsFinal Thoughtsq Patterns are relevant for all aspects of
software engineeringâ and for Business Process Reengineering
q Analysis patterns can be used acrosstraditional vertical business domains
q A model is not right or wrong, only moreor less useful
q Patterns are a starting point, not a finaldestination
q Still learning about teaching, using, anddiscovering patterns