Home Assignment 4 OCL



Similar documents
Appendix... B. The Object Constraint

Model Driven Security: Foundations, Tools, and Practice

UML TUTORIALS THE USE CASE MODEL

Design by Contract beyond class modelling

Execution of A Requirement Model in Software Development

Structure of Presentation. Stages in Teaching Formal Methods. Motivation (1) Motivation (2) The Scope of Formal Methods (1)

A Production Planning Problem

[Refer Slide Time: 05:10]

Etudes de cas en OCL avec l outil USE 2

Software Specification and Testing

Software Component Specification Using Design by Contract

Math Workshop October 2010 Fractions and Repeating Decimals

Sofware Requirements Engineeing

Use Cases. Massimo Felici. Massimo Felici Use Cases c

A UML 2 Profile for Business Process Modelling *

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

A Meeting Room Scheduling Problem

3. Mathematical Induction

Rigorous Software Development CSCI-GA

Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Indiana State Core Curriculum Standards updated 2009 Algebra I

Software Engineering Techniques

Sudoku puzzles and how to solve them

Introducing Formal Methods. Software Engineering and Formal Methods

Formally speaking: How to apply OCL

Analysis of the Specifics for a Business Rules Engine Based Projects

Case studies: Outline. Requirement Engineering. Case Study: Automated Banking System. UML and Case Studies ITNP090 - Object Oriented Software Design

Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model

Using Alloy and UML/OCL to Specify Run-Time Configuration Management: A Case Study

UML TUTORIALS THE COMPONENT MODEL

Network Model APPENDIXD. D.1 Basic Concepts

Algorithms are the threads that tie together most of the subfields of computer science.

Department of Computer Science, Institute for Software and Multimedia Technology OCL. by Example

Detecting Defects in Object-Oriented Designs: Using Reading Techniques to Increase Software Quality

Physical Design. Meeting the needs of the users is the gold standard against which we measure our success in creating a database.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

South Carolina College- and Career-Ready (SCCCR) Algebra 1

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

How To Write A Test Engine For A Microsoft Microsoft Web Browser (Php) For A Web Browser For A Non-Procedural Reason)

Roadmap. Software Engineering. Software Engineering. Project Life Cycle. Database. Project Lifecycle

FTS Real Time Client: Equity Portfolio Rebalancer

Chapter 1: Key Concepts of Programming and Software Engineering

1) Testing of general knowledge 25%. Each right question counts 1. Each wrong counts 0.5. Empty

Instant SQL Programming

Visual Basic Programming. An Introduction

Notes on Plagiarism: An Electrical Engineering and Computer Science Perspective

A Framework for the Semantics of Behavioral Contracts

CIS 771: Software Specifications. Lecture 1: Course Overview

III. Class and Object Diagrams

Python Programming: An Introduction To Computer Science

Mathematics. What to expect Resources Study Strategies Helpful Preparation Tips Problem Solving Strategies and Hints Test taking strategies

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

CSC 221: Computer Programming I. Fall 2011

The Set Data Model CHAPTER What This Chapter Is About

Mechanics 1: Vectors

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

River Dell Regional School District. Computer Programming with Python Curriculum

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

A SYSTEMATIC APPROACH FOR COMPONENT-BASED SOFTWARE DEVELOPMENT

Reading 13 : Finite State Automata and Regular Expressions

Role-based Authorization Constraints Specification Using Object Constraint Language

Informatica e Sistemi in Tempo Reale

QaTraq Pro Scripts Manual - Professional Test Scripts Module for QaTraq. QaTraq Pro Scripts. Professional Test Scripts Module for QaTraq

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Grade 6 Mathematics Assessment. Eligible Texas Essential Knowledge and Skills

Structural Analysis - II Prof. P. Banerjee Department of Civil Engineering Indian Institute of Technology, Bombay. Lecture - 02

UML-based Test Generation and Execution

SUBGROUPS OF CYCLIC GROUPS. 1. Introduction In a group G, we denote the (cyclic) group of powers of some g G by

Chapter II. Controlling Cars on a Bridge

Precisely Target the Right Audience

SECTION 10-2 Mathematical Induction

Introduction to SQL for Data Scientists

Discrete Math in Computer Science Homework 7 Solutions (Max Points: 80)

2. Basic Relational Data Model

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Discrete Optimization

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Organization of DSLE part. Overview of DSLE. Model driven software engineering. Engineering. Tooling. Topics:

Semantic Errors in SQL Queries: A Quite Complete List

Tips for writing good use cases.

Efficient Data Structures for Decision Diagrams

2014 HSC Software Design and Development Marking Guidelines

CRM Rules! User Guide. Version Prepared October, 2012 By: David L. Carr, President, Visionary Software

GContracts Programming by Contract with Groovy. Andre Steingress

Answer Key for California State Standards: Algebra I

16.1 MAPREDUCE. For personal use only, not for distribution. 333

MDA and Analysis of Web Applications

Verification of Good Design Style of UML Models

Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

Transcription:

Home Assignment 4 OCL This home assignment is about writing formal specifications using the Object Constraint Language. You will exercise formulating conditions/invariants on domain models that go beyond the expressiveness of UML class diagrams. Then, you will use OCL for writing contracts for methods, i.e., to specify behaviour. The main purpose of doing that is to get a feeling for textual formal specification languages like OCL, JML or Alloy, which can be used, amongst others, to provide better more precise documentation of software systems. Comments for the Corrector This week, we have added comments about how to correct only to some of the questions. Generally, when correcting you should not care too much about purely syntactic issues. It is more important that the constraints are logically correct, e.g., that the right collection operations are used (in the right way). Give comments when you subtract points, because the person that wrote the solution will not have the opportunity to ask you for comments personally. Exercise 1 (4p) This question is about strengthening the given domain model by formulating further properties in the Object Constraint Language. Order - sum:double - fee:double - orderedbooks Book - price:double - idnumber:int a) (1p) Give an OCL invariant that specifies that the sum attribute cannot be negative. context Order inv: sum >= 0 b) (1p) 1

Give an OCL invariant that specifies that the sum attribute will be zero if no books are ordered. context Order inv: orderedbooks->isempty() implies sum = 0 c) (1p) Give an OCL invariant that specifies that the sum attribute really describes the price of the books ordered. context Order inv: sum = orderedbooks->collect(price)->sum() using short-h notation: context Order inv: sum = orderedbooks.price->sum() d) (1p) Give an OCL invariant that specifies that different instances of Book have different idnumbers. A number of different solutions here: context Book inv: Book.allInstances()->forAll(b1, b2 b1 <> b2 implies b1.idnumber <> b2.idnumber) context Book inv: Book.allInstances()->forAll(b1, b2 b1.idnumber = b2.idnumber implies b1 = b2) context Book inv: Book.allInstances()->forAll(b b <> self implies 2

context Book inv: Book.allInstances()->isUnique(idNumber) b.idnumber <> self.idnumber) You can make use of the following OCL operations: OclType: allinstances() OclAny: object<>(object2) String: = Integer: <> Real: +, >=, Boolean: b1 implies b2, b1 b2 (b1,b2:boolean) Collection, Set, Bag, Sequence: collection-> sum() collection-> size() collection->collect(element:type <expr>) collection-> select (element:type <expr>) collection-> forall(element:type <expr>) collection-> exists(element:type <expr>) collection->isunique(element:type <expr>) collection-> iterate(element:typ1; result:type2 = <expr> <expr-with-element--result>) Exercise 2 (12p) This question continues exercise 3 4 from the first home assignment. The context is the following domain model, which is one possible solution to exercise 3 of that assignment: 3

One possible solution: Bank name 1.. Account balance interest PaymentRemarks date info remarks customer account 1 Customer status name associate 0..1 1 0..1 warrantor Address SteetName StreetNumber city country address 1 Income amount date income loan Loan amount interest payment 0..1 security own 0..1 House taxvalue loanfor 0..1 With help of the multiplicity one can constrain the domain model. But there are other conditions, business rules, which cannot be described by only a domain model using multiplicities. Such rules can be written in a precise manner using OCL. a) Invariants (1) (2p) Write the following constraint as an OCL invariant of concept Loan: If a loan has a warrantor, then the warrantor is an associate of the customer who has the loan. context Loan inv: warrantor->notempty() implies customer.associate->includes(warrantor) b) Invariants (2) (2p) 4

Write the following constraint as an OCL invariant of concept Loan: If a Loan has a House as security, then the Customer having the Loan must own that House. context Loan inv: security->notempty() implies security.customer = customer or context Loan inv: security->notempty() implies customer.own->includes(self.security) c) Invariants (3) (2p) Write the following constraint as an OCL invariant of concept Loan: If a Loan has a House as security, then that House must have a taxvalue (assessed value) of at least 20% of the amount of the Loan. context Loan inv: security->notempty() implies (security.taxvalue / amount) 100 >= 20 d) Pre-/Postconditions: Customer::getLoan() (2p) In order to simplify the following question, we assume that the number of instances of concept Income that are related with a customer shows how many times during the last 12 months the person got a salary. If there are, for example, 9 instances of Income related to a customer, then the customer got a salary in 9 out of 12 months. We start with refining the domain model into a class diagram. Therefore, an operation getloan():boolean is added to class Customer. 1 This operation is supposed to return whether a customer can be given a loan (true) or not (false). As a business decision, a customer can be given a loan if only if the following conditions hold (unless houses as securities or warrantors are involved, in this case the whole situation gets more complicated): 1 Whether this is good design is questionable, but this is not the point of this exercise... 5

The customer got a salary in each of the last 12 months. In each of the last 12 months, the salary was more than 14 000 kr. Give an OCL specification of Customer::getLoan() that expresses these conditions. context Customer::getLoan():Boolean post: result = (income->size() = 12 income->forall(amount>14000)) e) Pre-/Postconditions: Customer::addLoan() (4p) The following question is a difficult one... Good luck! As the next step, we create an operation addloan(amount:real, interest:real, payment:real):loan[0..1] for really adding a loan. The operation will again be added to class Customer. The result of the operation is either the loan instance that was created (if adding the loan was successful) or the empty set (otherwise). The preconditions of the operation have to express that the arguments have reasonable values. Decide yourself about what is reasonable, but also give a short justification for the conditions that you came up with. The effect of the operation is supposed to be the following: If the customer is directly allowed to get a loan (i.e., the conditions from d) are satisfied): A Loan object has been created, its attributes have the values that were given as arguments of addloan(), the object has been related with the customer. Otherwise: If the customer has an associate customer that is allowed to get a loan (again according to the conditions from d)): A Loan object has been created like in the first case, but in addition the associate has been added as a warrantor. Otherwise: No loan is added. Give an OCL specification of Customer::addLoan() that expresses all these conditions. Hint: Note that you can use the query Customer::getLoan() in OCL expressions. We consider the following values of the arguments as reasonable: 6

amount is positive. interest must not be negative, because the bank does not want to pay its customers for taking loans. The value 0 is possible might occur for very special customers... The monthly/yearly payment (whatever) must not be negative, must not be greater than the amount. context Customer::addLoan(p_amount:Real, p_interest:real, p_payment:real):loan[0..1] pre: p_amount > 0 p_interest >= 0 p_payment >= 0 p_payment <= p_amount post: (loan - loan@pre)->forall(amount = p_amount interest = p_interest payment = p_payment security->isempty() loanfor->isempty()) if getloan() then result->notempty() result.oclisnew() loan = loan@pre->including(result) result.warrantor->isempty() else if associate->exists(getloan()) then result->notempty() result.oclisnew() loan = loan@pre->including(result) associate->exists (war war.getloan() result.warrantor = war) else loan = loan@pre result->isempty() endif endif Comments for the Corrector Give up to 1p for reasonable pre-conditions that are correctly formalised (which must not exactly be the pre-conditions given as solution here). Give up to 1p for correctly distinguishing the different possible cases (warrantor, no warrantor, no loan at all). 7

Give up to 1p for correctly creating a Loan object, for assigning the attributes/associations amount, interest, payment, security, loanfor, for adding it to self.loan. Give up to 1p for correctly setting up the warrantor field of the newly created Loan object. (total 16p) 8