An association between class Flight and class Person, indicating that a certain group of persons are the passengers on a flight, will have multiplicity.

Slides:



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

The role of OCL in the Model Driven Architecture Jos Warmer Klasse Objecten
Semantics Static semantics Dynamic semantics attribute grammars
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.
1 The Object Constraint Language: Expressing Constraints in the UML (Most slides created by Robert B. France, Professor Department of Computer Science,
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.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
CS 355 – Programming Languages
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Object Constraint Language.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Irina Rychkova. 9/20061 Systemic approach towards model definition Model transformation semantics.
Software Testing and Quality Assurance
Axiomatic Semantics Dr. M Al-Mulhem ICS
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Describing Syntax and Semantics
Object Specification Moving towards a more precise specification of software.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
SEG4110 – Advanced Software Engineering and Reengineering TOPIC E Object Constraint Language (OCL)
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Understanding Advanced UML Concepts Gerd Wagner
Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are.
The Java Programming Language
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.
1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות.
4. The process specification (プロセス仕様) You will learn: (次の内容を学び) The concept of process specification (プロセス 仕様の概念) Notations for process specification (プロセス.
IM NTU Software Development Methods, Fall2006 Software Development Methods, Fall 2006 OCL 2006/12/ Object Constraint Language (OCL) Yih-Kuen Tsay.
Chapter 3 Part II Describing Syntax and Semantics.
Object Constraint Language
1 Kyung Hee University Constraints Spring Kyung Hee University Graphical Notations  Graphical notations are well suited for displaying structural.
Formal Methods in Software Engineering1 Today’s Agenda  Quiz 2 next class  Presentation Schedule  Quick Review  Build Models Using OCL.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Formal Methods in Software Engineering1 Today’s Agenda  Quiz 1 Return  Project Discussion  Quick Review  Finish Introduction to OCL.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Interpreting the Object Constraint Presented by: Ed Kausmeyer.
Jan Pettersen Nytun, UIA, page 1. Jan Pettersen Nytun, UIA, page 2 HISTORY COLLECTION TYPES AND QUERING IN OCL FORMAL LANGUAGE - STATEMENT EXAMPLES CONSTRAINTS.
UNIT-IV Designing Classes – Access Layer ‐ Object Storage ‐ Object Interoperability.
Analysis Classes Unit 5.
Used to help understand requirements more completely
Introduction to Python
Chapter 16 UML Class Diagrams.
Introduction to Computer Science / Procedural – 67130
Representation, Syntax, Paradigms, Types
The Object Constraint Language
Chapter 9, Object Design: Object Constraint Language
Chapter 9, Object Design: Specifying Interfaces
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Specifying Object Interfaces
Lecture 22 Inheritance Richard Gesick.
UML Class Diagram.
LECTURE 11: Specifying Systems – State Diag’s & OCL
Representation, Syntax, Paradigms, Types
Software Design Lecture : 15.
Chapter 6 Control Statements: Part 2
Representation, Syntax, Paradigms, Types
The Object Constraint Language
Language-based Security
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Representation, Syntax, Paradigms, Types
Java Statements B.Ramamurthy CS114A, CS504 4/23/2019 BR.
PHP an introduction.
Object Oriented System Design Class Diagrams
Introduction to UML - Prof. Prasad P. Mahale
CprE 185: Intro to Problem Solving (using C)
Chap 7. Advanced Control Statements in Java
Object Constraint Language (OCL)
Formal Methods in Software Engineering 1
Generics, Lambdas and Reflection
Introduction to UML - Prof. Prasad P. Mahale
Presentation transcript:

an association between class Flight and class Person, indicating that a certain group of persons are the passengers on a flight, will have multiplicity many (0..*) on the side of the Person class. This means that the number of passengers is unlimited. In reality, the number of passengers will be restricted to the number of seats on the airplane that is associated with the flight. It is impossible to express this restriction in the diagram. Flight flightNo: Integer availableSeats(): Integer Airplane numberOfSeats: Integer Person name: String 0..*1 flights plane 0..*flights 0..*passengers

In this example, the correct way to specify the multiplicity is to add to the diagram the following OCL constraint: context Flight inv: passengers->size() <= plane.numberOfSeats Flight flightNo: Integer availableSeats(): Integer Airplane numberOfSeats: Integer Person name: String 0..*1 flights plane 0..*flights 0..*passengers

A person may have a mortgage on a house only if that house is owned by him- or herself; –one cannot obtain a mortgage on the house of one's neighbor or friend. The start date for any mortgage must be before the end date. The ID card number of all persons must be unique. Person IDCardNo: Integer salary: Money House getMortgage(sum: Money security: House) value: Money Mortgage principal: Money monthlyPayment: Money startDate: Date endDate: Date 0..*1 houses owner 1security 0..*mortgages 0..* mortgages 1 borrower

A new mortgage will be allowed only when the person's income is sufficient. A new mortgage will be allowed only when the counter-value of the house is sufficient. Person IDCardNo: Integer salary: Money House getMortgage(sum: Money security: House) value: Money Mortgage principal: Money monthlyPayment: Money startDate: Date endDate: Date 0..*1 houses owner 1security 0..*mortgages 0..* mortgages 1 borrower

Value Added by OCL context Mortgage inv: security.owner = borrower context Mortgage inv: startDate < endDate context Person inv: Person::allInstances()->isUnique(socSecNr) context Person::getMortgage(sum : Money, security : House) pre: self.mortgages.monthlyPayment->sum() <= self.salary * 0.30 context Person::getMortgage(sum : Money, security : House) pre: security.value >= security.mortgages.principal->sum()

The Object Constraint Language is just a specification language. It obeys a syntax and has keywords. However, unlike other languages, it can't be used to express program logic or flow control. By design, OCL is a query-only language; it can't modify the model (or executing system) in any way. It can be used to express preconditions, postconditions, invariants (things that must always be True), guard conditions, and results of method calls. OCL can be used virtually anywhere in UML and is typically associated with a classifier using a note. When an OCL expression is evaluated, it is considered to be instantaneous, meaning the associated classifier can't change state during the evaluation of an expression.

Constraints on Classifiers Each OCL expression must have some sense of context that an expression relates to. Often the context can be determined by where the expression is written. For example, you can link a constraint to an element using a note. You can refer to an instance of the context classifier using the keyword self. For example, if you had a constraint on Student that their GPA must always be higher than 2.0, you can attach an OCL expression to Student using a note and refer to the GPA as follows: self.GPA >= 2.0

School 0..* 1 preReqs courses name: String tuition: float Teacher name: String salary: float Course title: String roomAssignment: String textBook: String courseLevel: int registerStudents(s:Student) :boolean getHonorsStudents() :Student[0..*] Student GPA: float dateOfBirth: Date yearOfGraduation: int tuitionPaid: boolean 1..* instructor students

Constraints if you had a constraint on Student that their GPA must always be higher than 2.0, you can attach an OCL expression to Student using a note to refer to the GPA as follows: self.GPA > 2.0 Note: –If you want to allow a GPA of less than 2.0 and send out a letter to the student’s parents in the event such a low GPA is achieved, you would model such behavior using a UML diagram such as an activity or interaction diagram.

The following invariant on Course ensures that the instructor is being paid: self.instructor.salary > 0.00

Business Rule The following expressions verify that a student’s tuition was paid before registering for a course and that the operation registerStudent returned true: context Course::registerStudent(s: Student): boolean pre: s.tuitionPaid = true post: result = true

We can name pre and post conditions by placing a label after the pre or post keywords: context Course::registerStudent(s: Student): boolean pre hasPaidTuition: s.tuitionPaid = true post studentHasRegistered: result = true

Postconditions can use keyword to refer to the value of some element before an operation executes. The following expression ensures that a student was registered and the number of students in the course has increased by 1. context Course::registerStudent(s: Student): boolean pre hasPaidTuition: s.tuitionPaid = true post studentHasRegistered: result = true AND self.students = + 1

We may specify the results of a query operation using the keyword body. Because OCL doesn’t have syntax for program flow, we are limited to relatively simple expressions. The following expressions indicate that the honors students are students with GPAs higher than 3.5. context Course::getHonorsStudents(s: Student): boolean body: self.students->select(GPA > 3.5)

Conditionals OCL supports basic Boolean expression evaluation using the if-then-else-endif keywords. The conditional are used only to determine which expression is evaluated; they can’t be used to influence the underlying system or to affect program flow. The following invariant enforces that a student’s year of graduation is valid only if she has paid her tuition: context Student inv: if tuitionPaid = true then yearOfGraduation = 2005 else yearOfGraduation = 0000 endif

OCL’s Logic Rules The boolean evaluation rules are: 1.True OR-ed with anything is true. 2.False AND-ed with anything is false. 3.False IMPLIES anything is True.

OCL’s Logic Rules For example, the following expression enforces that if a student's GPA is less than 1.0, their year of graduation is set to 0. If the GPA is higher than 1.0, Rule #3 applies, and the entire expression is evaluated as true (meaning the invariant is valid). context Student inv: self.GPA < 1.0 IMPLIES self.yearOfGraduation = 0000

OCL supports several complex constructs you can use to make your constraints more expressive and easier to write. You can break complex expressions into reusable pieces (within the same expression) by using the let and in keywords to declare a variable. You declare a variable by giving it a name, followed by a colon (:), its type, an expression for its value, and the in keyword. The following example declares an expression that ensures a teacher of a high-level course has an appropriate salary: context Course inv: let salary : float = self.instructor.salary in if self.courseLevel > 4000 then salary > else salary < endif