Presentation is loading. Please wait.

Presentation is loading. Please wait.

Schema Operators. State We can use the language of schemas to describe the state of a system, and operations upon it. Different aspects of the state --

Similar presentations


Presentation on theme: "Schema Operators. State We can use the language of schemas to describe the state of a system, and operations upon it. Different aspects of the state --"— Presentation transcript:

1 Schema Operators

2 State We can use the language of schemas to describe the state of a system, and operations upon it. Different aspects of the state -- and different aspects of a given operation -- can be described as separate schemas; these schemas may be combined in various ways using schema operators. In this way, we may factorise the description, identifying common aspects for re-use, and providing structure.

3 Schema operators

4

5

6

7 Same variable declared in both schemas must match the its type Otherwise the conjunction will be undefined

8 Schema conjunction allows specifying different aspects of a specification separately Combine them to form a complete description Adv: simple, well-structured, can be easily understood

9 Example From previous lecture : the schema for BoxOffice let say the theatre has premiere and standard performances. Let declared new variable of type Status to differentiate the kind of performances

10 Example let say we have a set friends who are currently registered as friends of the theatre. Only those customers who are friends may buy seats for the premieres If the current performance is a premiere, then seats may be sold only to friends

11 Example We use conjunction to describe an enhance box office It is equivalent to

12 Schema Inclusion Reuse the name of one schema in the declaration part of another When a schema name appears in a declaration part of a schema, the result is a merging of declarations and a conjunction of constraints.

13

14

15 Schema decoration

16 Suppose the state of a system is modelled by a schema State with two components a and b, and these are introduced under a constraint P State a : A b : B P Each object of schema type State represents a valid state : a binding of a and b in which predicate P is satisfied P forms part of state invariant for the system

17 Schema decoration to describe an operation upon the state; use two copies of State: one represents the state before the operation; the other represents the state afterwards. We use decoration to distinguish them State’ a’ : A b’ : B P[a’/a,b’/b]

18 Schema decoration We may describe an operation by including both State and State’ in the declaration part

19 Example The set of all valid states of box office system Each state is a binding of variable seating and sold; the state invariant insists that only allocated seats are sold, and the relationship between seats and customers remains functional

20 Example To describe the state of box office system after some operation Introduces seating’ and sold’ to correspond to the seat seating and the sales record after the operation has been performed.

21 Example Encapsulate all of the information in a single schema; schema representing the successful purchasing of seat s? by customer c?

22 Exercise You were given a schema named Library during the last week lecture. The schema shows state before operation. You are required to write another schema to show the state after operation. Then write another schema named LibraryState to show the merging of the schemas before and after operation

23 Input and Output An operation may involve inputs and outputs. These are declared in the normal way, although there is a convention regarding their names: - the name of an input should end in a question mark - the name of an output should end in an exclamation mark

24 Input and Output: example

25

26 s? is an input seat (name of seat); c? is the input customer (name of customer) buying s? the predicate s?  seating \ dom sold is to make sure that input seat is available for sale beforehand The predicate sold’ = sold  {s? ↦ c?}

27 We may add an output to our description of operation We use response from a free type of responses Response = ok | sorry And may be declared in a separate schema Success The effect of a successful purchase is Purchase 0  Success r! : Response r! = ok

28 exercise Use schema inclusion for schema Add_book_to_library_ok

29 Delta and Xi

30

31

32

33 exercise What should be in Add_book_to_library_ok now? write a schema to check if a book is already in the library by using  Library

34 Initialisation When using an abstract data type for a system, we should include a description of the initial state. An initialisation is a special operation for which the before state is unimportant. (does not refer to before state) Such an operation can be modelled by an operation schema that contains only a decorated copy of the state:

35 example Init_library Library’ books’ =  borrowers = 

36

37 Schema Disjunction If S and T are two schemas, then their disjunction S  T is a schema - whose declaration is a merge of the two declarations - whose constraint is a disjunction of the two constraints

38

39 example Schema to describe unavailable seat Schema to indicate a seat could not be sold Failure r! : Response r! = sorry

40 Can combine to the schemas to describe complete operation for purchase: Purchase ≙ (Purchase 0  Success)  (NotAvailable  Failure)

41 example For a complete schema to add a book to library is as below: Add_book_to_library ≙ Add_book_to_library_ok  Book_already_in_library

42 Exercise Write a complete schema to add a borrower to the library system. Please refer to the handout given to the class.


Download ppt "Schema Operators. State We can use the language of schemas to describe the state of a system, and operations upon it. Different aspects of the state --"

Similar presentations


Ads by Google