1 / 42

Schema Operators

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

thai
Download Presentation

Schema Operators

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. Same variable declared in both schemas must match the its type • Otherwise the conjunction will be undefined

  5. 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

  6. 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

  7. 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

  8. Example • We use conjunction to describe an enhance box office • It is equivalent to

  9. 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.

  10. Schema decoration

  11. Schema decoration • 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

  12. 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]

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

  14. 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

  15. 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.

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

  17. 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

  18. 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

  19. Input and Output: example

  20. Input and Output: example

  21. 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?}

  22. 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 Purchase0 Success r! : Response r! = ok

  23. exercise • Use schema inclusion for schema Add_book_to_library_ok

  24. Delta and Xi

  25. 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

  26. 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:

  27. example Init_library Library’ books’ =  borrowers = 

  28. 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

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

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

  31. 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

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

More Related