slides before 1st section divider

108
Slides before 1st Section Divider 随随随随随随随 (Things That Change with Time) 随随 随随 / Quantity 随 Unused Sectio n Space 2 随随随随随随 Unused Sectio n Space 3 Unused Sectio n Space 4 Unused Sectio n Space 1

Upload: bernard-oneill

Post on 30-Dec-2015

71 views

Category:

Documents


10 download

DESCRIPTION

数量 / Quantity 模式. Slides before 1st Section Divider. Unused Section Space 1. 随时间变化事物 ( Things That Change with Time) 模式. 扩展. 观察和测量模式. Unused Section Space 2. Unused Section Space 3. Unused Section Space 4. 观察和测量模式. 徐迎晓 复旦大学软件学院 [email protected]. 数量 /Quantity. class Person{ - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Slides before 1st Section Divider

Slides before 1st

Section Divider

随时间变化事物(Things That

Change with Time)模式

数量 / Quantity 模

Unused Section Space 2

观察和测量模

Unused Section Space 3

Unused Section Space 4

Unused Section Space 1

扩展

Page 2: Slides before 1st Section Divider

观察和测量模式

徐迎晓复旦大学软件学院

[email protected]

Page 3: Slides before 1st Section Divider

数量 /Quantityclass Person{

int height;

int weight;

}

Page 4: Slides before 1st Section Divider

Java 中已有的 NumberClass Number

Page 5: Slides before 1st Section Divider
Page 6: Slides before 1st Section Divider

数量

Page 7: Slides before 1st Section Divider

Quantity

Page 8: Slides before 1st Section Divider

arithmetic.

Page 9: Slides before 1st Section Divider

Java 中已有的 UnitCurrency

Page 10: Slides before 1st Section Divider

MoneyMoney 是数量的一种特殊实例

Page 11: Slides before 1st Section Divider

getterpublic class Money implements Comparable {

private BigInteger amount;private Currency currency;

public double amount() {return amount.doubleValue() / 100;

}

public Currency currency() {return currency;

}

Page 12: Slides before 1st Section Divider

constructorpublic Money(double amount, Currency currency) { this.amount = BigInteger.valueOf(Math.round(amount * 100));

this.currency = currency;}

public Money(long amount, Currency currency) {this.amount = BigInteger.valueOf(amount *

100);this.currency = currency;

}

public static Money dollars(double amount) { return new Money(amount, Currency.getInstance("USD"));}

Page 13: Slides before 1st Section Divider

+-public Money add(Money arg) { assertSameCurrencyAs(arg); return new Money(amount.add(arg.amount), currency, true);}public Money subtract(Money arg) {

return this.add(arg.negate());}void assertSameCurrencyAs(Money arg) {//Assert.equals("money math mismatch", currency, arg.currency);}

Page 14: Slides before 1st Section Divider

private Money(BigInteger amountInPennies, Currency currency, boolean privacyMarker) {// Assert.notNull(amountInPennies);// Assert.notNull(currency);

this.amount = amountInPennies;this.currency = currency;

}public Money negate() {

return new Money(amount.negate(), currency, true);}

Page 15: Slides before 1st Section Divider

*/public Money multiply(double arg) {

return new Money(amount() * arg, currency);}public Money[] divide(int denominator) {

BigInteger bigDenominator = BigInteger.valueOf(denominator); // 分母Money[] result = new Money[denominator];BigInteger simpleResult = amount.divide(bigDenominator);for (int i = 0; i < denominator; i++) {

result[i] = new Money(simpleResult, currency, true);}int remainder =

amount.subtract(simpleResult.multiply(bigDenominator)).intValue();

for (int i = 0; i < remainder; i++) {result[i] = result[i].add(new Money(BigInteger.valueOf(1),

currency, true));}return result;

}

Page 16: Slides before 1st Section Divider

> <public int compareTo(Object arg) {

Money moneyArg = (Money) arg;assertSameCurrencyAs(moneyArg);return amount.compareTo(moneyArg.amount);

}

public boolean greaterThan(Money arg) {return (this.compareTo(arg) == 1);

}

public boolean lessThan(Money arg) {return (this.compareTo(arg) == -1);

}

public boolean equals(Object arg) {if (!(arg instanceof Money))

return false;Money other = (Money) arg;return (currency.equals(other.currency) && (amount.equals(other.amount)));

}

Page 17: Slides before 1st Section Divider

单位的转换率

Page 18: Slides before 1st Section Divider

Class ConversionRatio{

Unit from, to;

Number number;

}

Page 19: Slides before 1st Section Divider

复合单位

Page 20: Slides before 1st Section Divider
Page 21: Slides before 1st Section Divider
Page 22: Slides before 1st Section Divider

Class CompoundUnit implement Unit{

Unit inverse[ ], direct[ ]; // 分母,分子}

Page 23: Slides before 1st Section Divider

数量模式为解决单位问题提供了有效的办法。建立分析模型时不应过早地考虑设计和实现

环境,而且要从概念上抓住各种细节,这样建立的分析模型才能更精确地描述需求。

Others范围 (Range) 模式随时间变化事物 (Things That Change with

Time) 模式

Page 24: Slides before 1st Section Divider

Patterns for things that change with time

Page 26: Slides before 1st Section Divider

temporal patternsNot just do we want to know the state of the world, we want to know the state of the world six months ago

what two months ago we thought the state of the world six months ago wasEffectivity patternTemporal Property pattern

Page 28: Slides before 1st Section Divider

Wellington. On Dec 1 1999 he begins employment with India Inc

Page 29: Slides before 1st Section Divider

Wellington. On Dec 1 1999 he begins employment with India Inc

As time continues he starts a new employment with Peninsula Inc on April 1 and ends his employment with India Inc on May 1.

Page 30: Slides before 1st Section Divider
Page 31: Slides before 1st Section Divider

Temporal Propertyremove the obvious effectivity date instead you use what looks like a regular

property , but with an accessor that takes a date as an argument

Page 32: Slides before 1st Section Divider

class Customer{private TemporalCollection addresses

= new SingleTemporalCollection();public Address getAddress(MfDate date) {

return (Address) addresses.get(date);}public Address getAddress() {

return getAddress(MfDate.today());}public void putAddress(MfDate date, Address value) {

addresses.put(date, value);}

Page 33: Slides before 1st Section Divider

providing a regular and predictable interface——accessor functions —— for dealing with those properties of an object that change over time

Page 34: Slides before 1st Section Divider

update information additive update

single put method that takes a timepoint and a new value

change XXX's address to YYY with effect from 23 August 2007

insertion update we had XXX moving in to address AAA in date

YYY, but we need to change that to ZZZ

Page 35: Slides before 1st Section Divider

two ways to implement Temporal Property collection of objects using Effectivity and

then manipulate this collection create a special collection class that

provides this behavior: a temporal collection

Page 36: Slides before 1st Section Divider

class TemporalCollection... private Map contents = new HashMap();public Object get(MfDate when) {

/** returns the value that was effective on the given date */Iterator it = milestones().iterator();while (it.hasNext()) { MfDate thisDate = (MfDate) it.next(); if (thisDate.before(when) || thisDate.equals(when))

return contents.get(thisDate);}throw new IllegalArgumentException("no records that

early");}public void put(MfDate at, Object item) {

/** the item is valid from the supplied date onwards */contents.put(at,item);clearMilestoneCache();

}

Page 37: Slides before 1st Section Divider

Temporal Property and Effectivity are not mutually exclusive patterns You might use address usage objects (using

Effectivity) to implement a Temporal Property interface

Temporal Property introduces the notion of referring to things with a time-based index, but takes it only so far as a single property. If you have many temporal properties on an object

? Snapshot and Temporal Object

Page 38: Slides before 1st Section Divider

Snapshot

gives you an object that refers to the state of the real object as at a point in time

A Snapshot is simply a view of an object with all the temporal aspects removed

Page 39: Slides before 1st Section Divider
Page 40: Slides before 1st Section Divider

class CustomerSnapshot... private Customer base;private MfDate validDate;public CustomerSnapshot (Customer base,

MfDate validDate) {this.base = base;this.validDate = validDate;

}public Address getAddress() {

return base.getAddress(validDate);}

Page 41: Slides before 1st Section Divider

Temporal Objecttwo roles: one continuity and several versions

several versionsAny time the value of any property of the

object changes, you get a new version you can imagine the versions as a list of

objects with an Effectivity to handle the date range.

one continuity

Page 42: Slides before 1st Section Divider
Page 43: Slides before 1st Section Divider
Page 44: Slides before 1st Section Divider

class CustomerVersion... private String address;private Money creditLimit;private String phone;

String address() {return address;}Money creditLimit() {return creditLimit;}String phone() {return phone;}

void setName(String arg) {_name = arg;}void setAddress(String arg) {address = arg;}void setCreditLimit(Money arg) {creditLimit =

arg;}

Page 45: Slides before 1st Section Divider

class Customer...

private TemporalCollection history = new SingleTemporalCollection();

public String name() {return current().name();}public String address() {return current().address();}public Money creditLimit() {return current().creditLimit();}public String phone() {return current().phone();}

private CustomerVersion current() {return (CustomerVersion)history.get();

}

Page 46: Slides before 1st Section Divider

In practice Effectivity used widely

Patterns like Temporal Property and Temporal Object work well because they hide much of the mechanics of temporal behaviorHowever Effectivity still is important: it is the right choice when people want an explicit object that is only valid for a particular time period.

Page 47: Slides before 1st Section Divider

Dimensions of Time a payroll system an employee has a rate of $ 100/day starting on

January 1 On February 25 we run the payroll with this rate On March 15 we learn that, effective on February

15, the employee's rate changed to $ 211/day.

what the rate was for February 25? $211 But often we cannot ignore that on Feb 25 we

thought the rate was $100,

Page 48: Slides before 1st Section Divider

record date | actual date| Dinsdale's rate Jan 1 Jan 1 $100/day Feb 15 Feb 15 $100/day Feb 25 Feb 15 $100/day Feb 25 Feb 25 $100/day Mar 14 Feb 15 $100/day Mar 15 Jan 1 $100/day Mar 15 Feb 15 $211/day Mar 15 Feb 25 $211/day

Page 49: Slides before 1st Section Divider

we make the corresponding adjustments in a payroll run on March 26. On April 4 we are told that the employee's our previous information was wrong and that the rate was actually changed to $255 on February 15 Now how do we answer the question "what was the employee's rate on February 25?".

Mar 26 Feb 25 $211/dayApr 4 Feb 14 $100/day Apr 4 Feb 15 $255/day Apr 4 Feb 25 $255/day

Page 50: Slides before 1st Section Divider
Page 51: Slides before 1st Section Divider

知识层和操作层的分离

通常的业务领域中每一种类型的对象就应该为其设计一个类

对每一种不同的几何图形如点、直线、三角形、四边形、圆等都会设计一个单独的类作为几何图形类的子类。

商业信息系统对象类型的数量可能会是相当多 随时可能有新的对象类型产生或消灭现实中一个对象可能有多种对象类型的特征

Page 52: Slides before 1st Section Divider

观察观察 (Observation)通过一定的方案获得一个对象的某个属性的

信息。

Page 53: Slides before 1st Section Divider

身高,体重,血型、血糖…

Page 54: Slides before 1st Section Divider

“ 病人”问题是一个动态属性问题,也就是要求在运行过程中动态决定对象具有哪些属性病人所做的检查项目是由观测类型决定的,

Page 55: Slides before 1st Section Divider

将类型信息放在对象的属性中来确定对象的类型。

Page 56: Slides before 1st Section Divider

观察

三个要素现象类型 (PhenomenonType/

ObservationType) 方案 (Protocol)值( Value )

测量 (Measurement )- 观察的值是一个数量种类 (Category )

现象 (Phenomenon )- 观察的值是一种类型

Page 57: Slides before 1st Section Divider
Page 58: Slides before 1st Section Divider

改进

Page 59: Slides before 1st Section Divider

测量

Page 60: Slides before 1st Section Divider
Page 61: Slides before 1st Section Divider

数据库元数据 + 数据 知识层 操作层

Page 62: Slides before 1st Section Divider

进一步改进离散值

Page 63: Slides before 1st Section Divider

观察

Page 64: Slides before 1st Section Divider
Page 65: Slides before 1st Section Divider
Page 66: Slides before 1st Section Divider
Page 67: Slides before 1st Section Divider

改进后

Page 68: Slides before 1st Section Divider
Page 69: Slides before 1st Section Divider
Page 70: Slides before 1st Section Divider
Page 71: Slides before 1st Section Divider
Page 72: Slides before 1st Section Divider
Page 73: Slides before 1st Section Divider
Page 74: Slides before 1st Section Divider
Page 75: Slides before 1st Section Divider
Page 76: Slides before 1st Section Divider
Page 77: Slides before 1st Section Divider
Page 78: Slides before 1st Section Divider

物资管理系统

Page 79: Slides before 1st Section Divider

“ 单据”类

Page 80: Slides before 1st Section Divider
Page 81: Slides before 1st Section Divider
Page 82: Slides before 1st Section Divider

教学系统

Page 83: Slides before 1st Section Divider
Page 84: Slides before 1st Section Divider
Page 85: Slides before 1st Section Divider
Page 86: Slides before 1st Section Divider
Page 87: Slides before 1st Section Divider

双时间记录

Page 88: Slides before 1st Section Divider

被否决的观察

Page 89: Slides before 1st Section Divider

假设,推理,临床观察

Page 90: Slides before 1st Section Divider
Page 91: Slides before 1st Section Divider
Page 92: Slides before 1st Section Divider

观察测量模式的扩展

Page 93: Slides before 1st Section Divider
Page 94: Slides before 1st Section Divider
Page 95: Slides before 1st Section Divider

TraittraitValue

PhysicalMeasuere Blood

HeightWeight

EyeColor HairColor Gender

ObservationPerson

Measurement

convertTo()

Quantityunitvalue

convertTo()

Page 96: Slides before 1st Section Divider

Class Diagram of the Basic Observation Model

Page 97: Slides before 1st Section Divider

TraittraitValue

Person

Measurement

convertTo()

Quantityunitvalue

convertTo()

Observation Observation Type

Page 98: Slides before 1st Section Divider

Instance Diagram with an example of a Party called Smith. Smith has a height observation with a value of 5 feet and an eye color observation with a value of blue. Note that the first Observation holds onto an ObservationType object which has a phenomenonType of height, and a Quantity object which holds onto the value of 5 for quantity and feet for units.

Page 99: Slides before 1st Section Divider
Page 100: Slides before 1st Section Divider

Composite Observations

Page 101: Slides before 1st Section Divider

Class Diagram of Composite

Observations

Page 102: Slides before 1st Section Divider

an observation about the blood pressure could be described in terms of a composite observation.

The “diastolic pressure” and the “systolic pressure” are the components of the “blood pressure” observation (as a composite).

Page 103: Slides before 1st Section Divider
Page 104: Slides before 1st Section Divider

Validations

Page 105: Slides before 1st Section Divider
Page 106: Slides before 1st Section Divider
Page 107: Slides before 1st Section Divider
Page 108: Slides before 1st Section Divider