210 likes | 221 Views
Learn about model-based software specification using Z, a mature and expressive notation that combines formal and informal descriptions and incorporates graphical highlighting.
E N D
(State) Model-Based Approaches II Software SpecificationLecture 36 Prepared by Stephen M. Thebaut, Ph.D. University of Florida
Specification using “Z” • Z is a mature and expressive notation for model-based specification. It combines formal and informal descriptions and incorporates graphical highlighting. • The basic building blocks of Z-based specifications are schemas. • Schemas identify state variables and define constraints and operations in terms of those variables. Software Engineering, 5th Edition. Chapter 11
Schemas • Schemas are comprised of three parts: name, signature, and predicate. • The signature declares (state) entities introduced in a schema and their type. • Signature declarations are given in the form identifier: type. • The predicate defines logical relationships between entities in the declaration. • Z is based on the predicate calculus + typed sets. Software Engineering, 5th Edition. Chapter 11
Graphical Layout of a Schema Schema Name Signature Predicate Software Engineering, 5th Edition. Chapter 11
Schemas (cont’d) • Schemas describe state entities or operations on state entities. • To describe state entities,declared variables comprise the entities while predicates specify their invariant properties. • To describe operations,declarations consist of initial and final state variables, inputs, and outputs, while predicates specify the relations among them. Software Engineering, 5th Edition. Chapter 11
modeled as natural numbers Container contents: N capacity: N contents capacity invariant property Example 1 Specification of a genericcontainer entity: Software Engineering, 5th Edition. Chapter 11
Indicator light: {off, on} reading: N danger_level:N light = on reading danger_level Example 1 (cont’d) Specification of a generic indicator entity: Software Engineering, 5th Edition. Chapter 11
Specification of a storage tank entity: Storage_tank Container Indicator reading = contents capacity = 500 danger_level = 50 Predicates on separate lines are separated by an implicit “AND”. Example 1 (cont’d) Software Engineering, 5th Edition. Chapter 11
Storage_tank contents: N capacity: N light: {off, on} reading: N danger_level:N contents capacity light = on reading danger_level reading = contents capacity = 500 danger_level = 50 Example 1 (cont’d) Expanded specification of a storage tank entity: Software Engineering, 5th Edition. Chapter 11
“Delta” indicates that values of one or more variables will be changed. “?” indicates that amount is an INPUT. Fill-OK Storage-tank amount?: N contents + amount? capacity contents’ = contents + amount? “dash” indicates the value of contentsAFTER the operation Example 1 (cont’d) Specification of anominalstorage tankfill operation: Software Engineering, 5th Edition. Chapter 11
“Xi” indicates that NO variables will be changed by the operation. “!” indicates that r is an OUTPUT. OverFill Storage-tank amount?: N r!: seq CHAR capacity < contents + amount? r! = “Insufficient tank capacity – Fill cancelled” Example 1 (cont’d) Specification of an exceptional storage tank fill operation: Software Engineering, 5th Edition. Chapter 11
Fill Fill-OK V OverFill Example 1 (cont’d) Complete specification of the storage tank fill operation: Software Engineering, 5th Edition. Chapter 11
“Powerset Book”: the set of sets of books set of books held by library Library stock: Book onLoan: Book Borrower set of (book, borrower) pairs dom onLoan stock books on loan are a subset of existing stock Example 2 Specification of a simpleLibrary system: Each book on loan is mapped to a borrower. Note use of typed sets. G Kontoya and I. Sommerville 1998
Borrow Library book?: Book reader?: Borrower book? stock book? dom onLoan onLoan’ = onLoan {(book?, reader?)} stock’ = stock Example 2 (cont’d) Specification of theborrow operation: G Kontoya and I. Sommerville 1998
New Library book?: Book stock’ = stock {book?} onLoan’ = onLoan Example 2 (cont’d) Operation for adding a new bookto current stock: G Kontoya and I. Sommerville 1998
Return Library book?: Book book? dom onLoan dom onLoan’ = dom onLoan book? stock’ = stock Example 2 (cont’d) Operation for returning a bookto the library: “Overriding” operator G Kontoya and I. Sommerville 1998
Exercise 4 Modify the storage tank specification by adding a fill warning light which indicates when the tank is close to capacity. This should be switched on when the contents are some high percentage of the capacity. Software Engineering, 5th Edition. Chapter 11
Key Points • Model-based specification relies on a state modelof the system using mathematical entities such as the predicate calculus and typed sets. • Functions / operations may be specified by defining their effect on system state. Software Engineering, 5th Edition. Chapter 11
Key Points (cont’d) • It is normal to specify functions / operations incrementally and then combine the fragments to produce a complete specification. • Z specifications are comprised of a number of schemas that introduce typed names and define predicates over those names. They are distinguished from surrounding text by graphical highlighting. Software Engineering, 5th Edition. Chapter 11
Key Points (cont’d) • Schemas are building blocks which may be combined and used in other schemas. The effect of including schema A in schema B is that schema B inherits the names and predicates of schema A. Software Engineering, 5th Edition. Chapter 11
(State) Model-Based Approaches II Software SpecificationLecture 36 Prepared by Stephen M. Thebaut, Ph.D. University of Florida