状态定义
对每一个带有状态模型的类型,我们必须能够区分类型不同属性的状态(实践中,状态定义的过程引导我们
细化状态模型,特别是类似属性这样的细节)。
Reservation(预订)
v : Reservation
-- A reservation is pending if 一个预订处于等待如果
v.pending =
-- there’s no copy on hold for the reservation 没有为这个预订保留拷贝
v.heldCopy -> isEmpty
-- and it’s not been fulfilled or expired or cancelled 没有被满足、失效或取消
and v.whenFulfilled -> isEmpty
and v.whenExpired -> isEmpty
and v.whenCancelled -> isEmpty
and
-- a reservation is fulfillable if 一个预订处于满足状态如果
v.fulfillable =
-- there is a copy on hold for the reservation 有一个拷贝为这个预订预留
v.heldCopy -> notEmpty
and
-- a reservation is cancelled if 一个预订被取消如果
v.cancelled =
-- there is a timepoint at which it was cancelled 在某一时间被取消
v.whenCancelled -> notEmpty
and
-- a reservation has expired if 一个预订失效如果
v.expired =
-- there is a timepoint at which it expired 在有效期结束的时间
v.whenExpired -> notEmpty
and
-- a reservation is fulfilled if 一个预订被满足如果
v.fulfilled =
-- there is a fulfilling rental 一个出租完成
v.fulfillingRental -> notEmpty
Copy(拷贝)
c : Copy
-- A copy is available for rent if 一个拷贝可以出租如果
c.forRent =
-- it does not have a current rental没有被出租
c.currentRental -> isEmpty
-- and it is not on hold for a reservation且没有为预订保留
and c.~heldCopy -> isEmpty
and
-- a copy is on hold for a reservation if 一个拷贝为预订保留如果
c. onHold =
-- it does not have a current rental没有被出租
c.currentRental -> isEmpty
-- but it is on hold for a reservation但为一个预订保留
and c.~heldCopy -> notEmpty
and
-- a copy is out on rent if一个拷贝在出租如果
c.rented =
-- it has a current rental已经被出租
c.currentRental -> notEmpty