290 likes | 537 Views
Promotion. Promotion. Promotion is a structuring technique that may be used whenever the state of a system contains multiple, indexed instances of the same component.
E N D
Promotion • Promotion is a structuring technique that may be used whenever the state of a system contains multiple, indexed instances of the same component. • It is most useful when several operations are possible upon the component, and their effect is independent of the index: that is, their effect is the same for each instance.
Example1 • The state of a game of trivial pursuit might be described using the following pair of schemas:
Example1 • The change in state associated with a single player answering a scoring question correctly could be described by:
Example1 • The change in local state - in the individual player's score - could be described by
Example1 • The following mixed operation identifies a particular local score; one of the copies indexed by score:
Example1 • The following operation describes the change in global state that accompanies such a correct answer: • Removing the extra names from the declaration, we obtain a global operation schema:
Promotion Schema • If Local describes a copy of the local state and Global describes a copy of the global state, then a promotion schema Promote will contain decorated and undecorated copies of both Local and Global. • If LocalOperation contains decorated and undecorated copies of Local, then we may promote LocalOperation to the global operation
Example2 • Each mailbox is a binding:
Example2 • A local operation:
Example2 • A promotion schema:
Example2 • A global operation:
Example2 • A global operation (without promotion):
Example3 A local operation:
Example • We wish to describe a library of musical recordings on tape or compact disc. We shall call this system as AudioLib. We want to attach a loan category to each recording copy and we want to maintain a record of the date on which the copy was loaned out.
Example • For this system the set Recording is defined by a schema so that the members of this set have a particular structure Recording cat : Category loans : seq Date rec : RecordingDetails • Date is a given set and RecordingDetails is either a given set or a schema type defined elseware • Two loan categories: Category ::= Loanable | Restricted
Example • A given set of identifiers used to identify uniquely each distinct physical tape or compact disc in AudioLib stock [RecId]
Example • We define the abstract state for the AudioLib system AudioLib stock : RecId ↛Recording out : RecId ↛Listener listeners : Listener dom out dom stock ran out listeners r : dom out (stock r).cat = Loanable
Example • The predicate part of this schema says that: - only items of stock can be out on loan - loans can only be made to registered listeners - items out on loan must be loanable and not restricted to the library
Example • We define an operation to change the loan category of a Recording ChangeCategory Recording newcat? : Category report! : Report cat ≠ newcat? (report! = Ok cat’ = newcat?) cat = newcat? (report! = NoChange cat’ = cat?) loans’ = loans rec’ = rec
Example • To promote operations on individual Recordings to be operations on the AudioLib abstract state, we factored using promotion; we define a promotion schema Promote AudioLib Recording rcid? : RecId rcid? dom stock Recording = stock rcid? stock’ = stock {rcid? ↦ Recording’}
Example • The constraint Recording = stock rcid? ensures that Recording concerned is the one corresponding to stock rcid? • The constraint stock’ = stock {rcid? ↦ Recording’} ensures that stock is unchanged except that rcid? Is now associated with the modified Recording • we could define an operation ChangeRecordingCategas: ChangeRecordingCateg ≙ Recording ChangeCategory Promote