1 / 50

IS351-System Analysis

Learn about the Object Constraint Language (OCL) and how it can help improve documentation, precision, and clarity in your object-oriented models. Explore OCL types, rule basics, checking attribute values, implies rules, rules across associations, rules on collections, and more.

henryk
Télécharger la présentation

IS351-System Analysis

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. IS351-System Analysis Lab 7: Object Constraint Language (OCL)

  2. Object constraint language (OCL) • What is constraint? A constraint is a restriction on one or more values of (part of) an object-oriented model or system e.g: class diagram. • Why add constrains to model? • Better documentation • More precision • More cleared and understandable UML models

  3. OCL Types

  4. OCL characteristics: • OCL constraints are declarative • They specify what must be true not what must be done • OCL constraints have formal syntax and semantics • OCL constraints have no side effects • Evaluating an OCL expression does not change the state of the system • Are evaluated in a specified context, either a class or an operation • All constraints apply to all instances. • OCL expression return true or false.

  5. OCL Rule Basics • Need to define five things for a rule • Context: The classifier with which the rule is associated • Type: Whether it is invariant, Pre, or post condition. • Name: The name of the rule • OCL: The rule expressed precisely in OCL • Error Message: A textual description of the business rule using the vocabulary of the business user. *Mandatory fields are underlined

  6. Example • Class: • Constraint: balance must be greater than 1000 • Syntax: • ContextSavingsAccount • InvbalanceCheck: Balance>1000 • --@error The balance must be greater than Zero SavingsAccount balance > 1000 Expression Context

  7. Syntax

  8. Rule Types • Checking Attribute Values • Implies / if …then rules • Rules across classes • Rules on collections

  9. 1. Checking Attribute Values 1-to-m OR m-to-m Person-Company All persons’ salary>1000 There is a person’s salary>1000 1-to-1 Person-Company Context Person Inv: self.employment->exists(salary > 1000) Context Person Inv:self.employment->forAll(salary > 1000) Context Person Inv: self.employment.salary > 1000

  10. 2. Implies Rule • Used for rules of form ‘if … then …’ • Constraint: If the amount of a Payment is greater than 1000, securityDetails must be provided. Context Payment Inv: self.amount > 1000 implies securityDetails<>null

  11. 3. Rules Across Associations • The payer Party and the recipient Party to a payment cannot have the same name Context Payment Inv: self.payer.name <> self.recipient.name

  12. 3. Rules Across Associations • Constraint: The number of guests in each room doesn’t exceed the number of beds in the room. Context Room Inv: self.numberOfBeds >=guest -> size() • Indicates a set of Guest class instances • Points at current instance as this in java

  13. 4. Rules on collections • Whenever the link in a constraint results in a set collection of objects, you can use one of the collection operations by putting an arrow between the rolename and the operation • Three different collections: • Set: Every element can appear only once • Bag: elements can appear more than once (also called multiset) • Sequence: A multiset, in which the elements are ordered (ordered Bag) • Syntax: • collection->operation(arguments)

  14. Collection operations • size(): number of elements in the collection • isEmpty(): True, if the collection is empty • notEmpty(): True, if the collection is not empty • sum(): The addition of all the elements in the collection • count(object): number ofoccurrences of theobject in the collection • includes(object): True if the object is an element of the collection • includesAll(collection): True if all elements of the parameter collection are members of the collection

  15. Collection operations • collect(): Makes a projection on object attributes, returns set of collection • excludes(object): True if the object is not an element of the collection • excludesAll(collection): True if all elements of the parameter collection are not members of the collection • forAll(expression) True if for all elements expression is true (expression must be a Boolean expression) • select(expr:OclExpression): Subset of all elements of the collection, for which the OCL expression expr is true

  16. 4. Rules on collections • Example Constraint: There must be at least one payment with value greater than 100 US dollars included in the bulk payments. Context BulkPayments Inv: self.payment->exists(p | p.amount > 100)

  17. recursive relationship • Constraint: A course can’t be a requirement for itself  Context Course Inv: < > self.requirements->includes (self) Context Course Inv: self.requirements->excludes (self)

  18. Exercise • Question 1: • Modules can be taken iff they have more than seven students registered Context Module Inv: self.taken_by->size() > 7

  19. Exercise • Question 2: • The assessments for a module must total 100% Context Module Inv: self.set_work.collect(weight)->sum ( ) = 100

  20. Exercise • Question 3: • Students must register for 120 credits each year Context Student inv: self.takes.collect(credit)->sum ( ) = 120

  21. Exercise • Question 4: • Students must take at least 90 credits of CS modules each year Context Student Inv: self.takes->select(code.substring(1,2)=‘CS’).collect(credit)-> sum() >=90

  22. Exercise • Question 5: • All modules must have at least one assessment worth over 50% Context Module Inv: self.set_work->exists (weight > 50)

  23. USE case tool Tutorial

  24. Steps to open USE tool (1) Open use.bat file

  25. Steps to open USE tool (2.1) CMD

  26. Steps to open USE tool (2.2) GUI

  27. Define classes and associations • We will define a simple class diagram containing 2 classes and 1 association

  28. Define OCL rules • We will define 2 OCL Constraints on class diagram • the student GPA shouldn't be greater than 4 • the student GPA should be greater than or equal to the department minimum GPA • Open a new Notepad file and define the classes, associatoin and OCL rules. After finishing, save the file with <.use> extension

  29. Steps to open USE tool (3) Open file: University.use

  30. Open views • You can open the view you want from the upper menu • We will open 4 views: object count, link count, class invariant and object diagram • You can also open the class diagram view to view the class diagram

  31. Steps to open USE tool (4) Controls

  32. Steps to open USE tool (5) Create new object

  33. Adding objects • We will add 6 objects • 4 objects for the departments (InformationSystem, ComputerScience, InformationTechnology, DecisionSupport) and 2 students (S1, S2) • From the menu state choose -> create object • Select the class and add the object • You will notice the change in the number of objects in object count

  34. Steps to open USE tool (6) New object name

  35. Steps to open USE tool (7.1) Many objects created

  36. Steps to open USE tool (7.2) Multiple Class’s Objects

  37. Steps to open USE tool (8) Evaluation Browser for Errors

  38. We can double click any object and modify its attribute • We should also link the 6 objects together to solve the violation problem • Insert the following command in the cmd window: • !insert (S1,InformationSystem) into enrolledIn • !insert (S2,InformationSystem) into enrolledIn • !insert (S2,InformationTechnology) into enrolledIn • !insert (S2,ComputerScience) into enrolledIn • !insert (S1,DecisionSupport) into enrolledIn

  39. Steps to open USE tool (9) Trial to solve Errors using OCL

  40. Steps to open USE tool (10) Results of associations

  41. Validate expressions • If we try to validate the OCL expressions we entered • We will find in class variant view that student GPA OCL return false • Modify the GPA of S1 to be 3 to remove violations

  42. Steps to open USE tool (11.1) Identifying GPA for obj1

  43. Steps to open USE tool (11.2) Identifying GPA for obj2

  44. Steps to open USE tool (11.3) Identifying min GPA for obj1

  45. Steps to open USE tool (11.4) Identifying min GPA for obj2

  46. Steps to open USE tool (11.5) Identifying min GPA for obj3

  47. Steps to open USE tool (11.6) Identifying min GPA for obj4

  48. Steps to open USE tool (11.7) Multiple Enrollment Violation

  49. Steps to open USE tool (11.7) Violation-free model

More Related