© 2004 Benet Devereux Lecture #4 OCL and SCR/Parnas Tables.

Slides:



Advertisements
Similar presentations
Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur.
Advertisements

Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 Summer school on Formal Models.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Design by Contract.
Semantics Static semantics Dynamic semantics attribute grammars
Copyright , Doron Peled and Cesare Tinelli. These notes are based on a set of lecture notes originally developed by Doron Peled at the University.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
OCL2 April A presentation of OCL 2 Object Constraint Language Christian Hein, Fraunhofer FOKUS April 2006.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
CS 355 – Programming Languages
Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Copyright W. Howden1 Lecture 13: Programming by Contract.
1 Specifying Object Interfaces. 2 Major tasks in this stage: --are there any missing attributes or operations? --how can we reduce coupling, make interface.
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
Detail Design Extending UML and Object Design. Object Design.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
SEG4110 – Advanced Software Engineering and Reengineering TOPIC E Object Constraint Language (OCL)
1 The Object Constraint Language Jos Warmer and Anneke Kleppe. OCL: The Constraint Language of the UML, Journal of Object-Oriented Programming, 2(2):10-13,
1 COSC 4406 Software Engineering COSC 4406 Software Engineering Haibin Zhu, Ph.D. Dept. of Computer Science and mathematics, Nipissing University, 100.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
A Z Approach in Validating ORA-SS Data Models Scott Uk-Jin Lee Jing Sun Gillian Dobbie Yuan Fang Li.
Analyzing the Requirements with Formal Specifications Vienna Development Method Specification Language (VDM-SL) Book: Formal Software Development From.
1COM6030 Systems Analysis and Design © University of Sheffield 2005 COM 6030 Software Analysis and Design Lecture 10 – Classes and operations Dr Richard.
111 Writing Protocols in OCL CS 4311 Jos B. Warmer and Anneke G. Kleppe, OCL: The Constraint Language of the UML, JOOP, May Jos B. Warmer and Anneke.
An introduction to specification in VDM-SL At the end of this lecture you should be able to: write a formal specification of a system in VDM-SL; correlate.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות.
Requirements Engineering Methods for Requirements Engineering Lecture-30.
4. The process specification (プロセス仕様) You will learn: (次の内容を学び) The concept of process specification (プロセス 仕様の概念) Notations for process specification (プロセス.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
IM NTU Software Development Methods, Fall2006 Software Development Methods, Fall 2006 OCL 2006/12/ Object Constraint Language (OCL) Yih-Kuen Tsay.
ISBN Chapter 3 Describing Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Chapter 16: UML Class Diagrams
Chapter 5 System Modeling. What is System modeling? System modeling is the process of developing abstract models of a system, with each model presenting.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
Types and Programming Languages
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Interpreting the Object Constraint Presented by: Ed Kausmeyer.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Defects of UML Yang Yichuan. For the Presentation Something you know Instead of lots of new stuff. Cases Instead of Concepts. Methodology instead of the.
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
Used to help understand requirements more completely
The Object Constraint Language
Specifying Object Interfaces
LECTURE 11: Specifying Systems – State Diag’s & OCL
Semantics In Text: Chapter 3.
The Object Constraint Language
Presentation transcript:

© 2004 Benet Devereux Lecture #4 OCL and SCR/Parnas Tables

© 2004 Benet Devereux Preamble ● Previously we have discussed object constraints in an informal way – This is fine for elicitation dialogue – And for model inspection and walkthroughs ● More formality is needed for – Formal analysis – Automatic prototype building ● Programming languages are formal! – Why introduce an intermediate formal language? – Declarative specifications avoid implementation bias

© 2004 Benet Devereux What, not How, Revisited ● Object model should describe the logic of domain activities, not algorithms ● It can be argued that skilled developers can abstract from descriptions in an imperative language – If a specification contains a call to sort(), it is clearly understood that this stands for a declarative specification of sorting, which everyone understands – For less familiar tasks, separating implementation from the purpose becomes harder, even with comments

© 2004 Benet Devereux Tools for Requirements Modeling ● In UML: – Object Constraint Language (OCL) – Statecharts ● Outside UML: – Parnas tables ● Implemented in Software Cost Reduction (SCR*) tool – Data-flow modeling (very old, but still used) ● Elements: processes and data-stores ● Relations: data passes between elements – Processes transform, stores simply record

© 2004 Benet Devereux Object Constraint Language ● Developed originally by IBM Insurance division – For modeling business logic in a formal but readable way – Has roots in Syntropy method of Cook and Daniels (1994) ● Now part of UML 1.5 standard – Syntax and semantics for other parts of UML are now defined using OCL

© 2004 Benet Devereux Characteristics of OCL ● Subset of typed first-order logic – Existential and universal quantification over elements of container objects is allowed –.. and over all instances of a class ● Expressions are side-effect-free – No x++ > 10 allowed ● Typed – All expression and terms have type; classes form a type hierarchy, allowing casting using oclAsType () function

© 2004 Benet Devereux What OCL Is For ● Specifying invariants on classes and types in the object model ● Describing preconditions, postconditions, and invariants for operations ● As a language for navigating through associations (similar to Xpath)

© 2004 Benet Devereux What OCL Isn't For ● Describing algorithms – Use the implementation language or pseudocode ● Specifying dynamic behaviour – Use UML state-charts

© 2004 Benet Devereux OCL Types ● Basic types – Boolean, Integer, Real, String ● Note this is a specification language, so integers are of arbitrary magnitude, and reals are real and not floats! ● Integers are a subtype of Reals ● Enumeration types – OCL treats enumerations as Singleton classes with an attribute for each value – Enumeration types appear in the object model, labeled with the > stereotype

© 2004 Benet Devereux OCL Types, continued ● Parameterized container types – Let T be a type – Set(T), Sequence(T), Bag(T), Collection(T) are types – All container types are subtypes of Collection(T) – Bag(T) is a multiset of type T ● Object types – Object type hierarchy follows class hierarchy – There is a superclass (what's it called) for all objects

© 2004 Benet Devereux Expressions ● Valid – 1+2*34 -- type Integer, value 69 – 'Foo'.concat('bar') – type String, value 'Foobar' – – type Real (highest common supertype) – 5 < 2 – type Boolean, value False – True or False – type Boolean, value True ● Invalid – 34 and True – 1 + 'motorcycle' – Color::green * 3

© 2004 Benet Devereux Contexts ● Every OCL statement requires a context ● Class context: – context class ● Named class context – Context c:class – Can refer to instance throughout statement ● Operation context – Context Class::operation (p1:Type,..) : ReturnType

© 2004 Benet Devereux Attribute Properties ● Class context: – context Company inv: – self.numberOfEmployees > 50 – or – context c: Company inv: – c.numberOfEmployees > 50 ● Invariants may be named: – context Company inv enoughEmployees – c.numberOfEmployees > 50 ● All invariant expression are of Boolean type!

© 2004 Benet Devereux Operation Properties ● result refers to the returned value – context Circle::area():Real – pre: True – post: result = pi * * 2)^2 ● Preconditions and postconditions may be given names – pre parametersOK:... – post resultOK:.. ● Not clear yet why! – But may be useful in coping with inheritance

© 2004 Benet Devereux Recursion ● You may refer to operations recursively – context factorial(n: Integer):Integer – pre: n >= 0 – post: if (n == 0) then result=1 else result = n*factorial(n-1) ● This is, of course, hazardous.. – Would be better to give the declarative definition, but this requires set-comprehension not included in OCL – Too much implementation bias! – Harder for stakeholders to read

© 2004 Benet Devereux Pre/Post Variables ● We may want to refer to both before and after versions of the object in a postcondition – After variables are unmarked – Before variables have ' catenated to the end ● If attribute 'x' is an object.. – retrieves the object pointed to by x at the start of the operation – retrieves the after value of the attribute y of the object referred to by x at the start

© 2004 Benet Devereux Some Intuition on This.. ● Consider a returnBook(b: Book) operation in a library system – A postcondition is that the book that was signed out is now in state 'Returned' – This is the right idea, but of course we can just refer to b! ●.. or a fire() method for course instructors – All courses previously taught by the instructor must still have an instructor when the fire() method finishes – The details of the decision are left unspecified; but the necessity of the decision is encoded

© 2004 Benet Devereux Creation and Destruction ● Recall objects may be created or destroyed during an operation – Referring to the pre-value of an object created during the operation is undefined – As is the post-value of a destroyed object – If an object x is created during an operation, x.oclIsNew() holds in the postcondition ● Sadly, no symmetric predicate for destroyed objects

© 2004 Benet Devereux Navigation Expressions ● Each association has a role-name – Course -> Teacher “instructor” – Teacher -> Course “coursesTaught” ● One-to-one association navigation is obvious – In the context of type Course, self.instructor retrieves the associated Teacher ● One-to-many / one-to-(zero or one) – Same syntax ( self.coursesTaught ) –.. but retrieves a Collection of the association target type

© 2004 Benet Devereux Working with Collections ● Basic operations – size() – includes(x) – count(x) – how many times x appears – includesAll(c) – subset – sum() -- if type is integer or real – exists(expr) – forAll(expr) – select(expr) – subcollection that satisfies expr ● Syntactic sugar.. – isEmpty(), excludes(x)...

© 2004 Benet Devereux The Collect Expression ● Create a new collection by evaluating an expression over each member of a collection – self.teachingAssistants- >collect(supervisor) – Equivalently ● self->teachingAssistants->collect(ta | ta.supervisor) ● self->teachingAssistants->collect(ta: gradStudent | ta.supervisor) ● Principally used to navigate associations, but is more general

© 2004 Benet Devereux SCR (Software Cost Reduction) ● Specify observable behaviour of system ● Monitored variables (under environment control) and controlled variables (under system control); including ● Based on Parnas tables – Note: not an object-oriented notation! Though nothing prevents us from using it in an OO setting – Treat each object as a subsystem: the sending of a message from A to B is a controlled variable of A, and a monitored one of A

© 2004 Benet Devereux Basic Concepts ● Types: Boolean, Integer, Enumerated (values must be specified) ● Discrete time model – values change instantly from one time step to the next ● A condition holds at one or more time steps; for instance, speed > 65 ● An event spans two time steps; for means that the value of Boolean buttonPressed goes from False to True

© 2004 Benet Devereux Mode Transition Tables Source Mode Destination Mode > max) ACOn < min) HeatOn.... ● Conditions for the same source mode must be disjoint – But not necessarily covering; if no event triggers a mode transition, the mode stays the same

© 2004 Benet Devereux Event Tables Controlled variable: Fan Mode class: Thermostat Fan'= on off Off ACOn HeatOn NEVER < 5)

© 2004 Benet Devereux Condition Tables Controlled Variable: powerLED Off ACOn, HeatOn on off FALSE TRUE FALSE

© 2004 Benet Devereux Domain Assertions ● Can be either state invariants (holding at every point in time) or transition invariants – State invariant: min < max (not allowed to set minimum temperature above maximum temperature) ● Note this may still be a design obligation! – Transition invariant: !( (temp > max) && (temp' < min))

© 2004 Benet Devereux Caveat ● Table notation allows formal analysis using SCR Toolset ● However, this depends on fixing the number of objects of each type!

© 2004 Benet Devereux The Story so Far ● Have started modeling requirements, not just eliciting ● Models have predictive power – Specify behaviour of objects – Can automatically check for erroneous behaviour – Check for inconsistencies in description, report to stakeholders ● Important: formal analysis != proof of correctness!