A Visualization of OCL using Collaborations P. Bottoni, F. Parisi-Presicce, University of Rome M. Koch, PSI Berlin G. Taentzer, Technical University of Berlin 1
A fictitious Dialog on OCL We use UML for our OO-development. Look! Great! But why do you describe all the constraints by natural language? Why don t you use OCL? This would avoid ambiguties! OCL? Oh, it s too difficult! I don t understand all the formula stuff. Would you use it, if it is also expressed by diagrams? Maybe. 2
How to visualize OCL? Start from the graphical elements of the UML notation. Derive new notation from the UML core notation where needed. Propose shortcuts for complex visualizations. Limit the size of a diagram. We depart from collaborations. 3
Running Example: egovernment certificate passports or ID cards Resident register inhabitants register the birth of a child Registration office 4
The Business Object Model <<enumeration>> StateOfApartment sole main second future <<enumeration>> KindOfCare father mother other Address attrstateofapartment: 0..* StateOfApartment attrdateofmovein: Date attrdateofmoveout: Date NaturalPersonCare attrkind: KindOfCare 0..* +statutoryagent 1 NaturalPerson attrfamilyname: String attrsex: String attrdateofdeath: Date Inhabitant attrstate: StateOfInhabitant <<enumeration>> StateOfInhabitant resident unknown known died Birth +birth attrbirthdate: Date attrbirthplace: String 1 0..4 +citizenship State attreu: Boolean attrcitizenship: String 5
egovernment Constraints Sample constraints: The birth date of a person comes before the date of moving into an apartment. The birth date of a mother/father has to preceed the birth date of her/his child. If a person has several citizenships, they must be different. A natural person without a state of inhabitation does not have an address. 6
Outline Visualization of OCL constraints: Constraints on object properties Collections Logical expressions Related work and conclusions 7
Constraints on Object Attributes The birth date of a person comes before the date of moving into an apartment: contextnaturalperson inv: self.birth.attrbirthdate < self.address.attrdateofmovein inv : Address /self : NaturalPerson /self: NaturalPerson birth : Birth attrdateofmovein = x attrbirthdate = y y < x 8
Constraints on Object Methods The age of a person has to be the current date minus the birth date. context NaturalPersoninv: self.getage() = currentdate() - self.birth.attrbirthdate inv a := getage() /self: NaturalPerson : Birth attrbirthdate = b a = currentdate() - b 9
Visualizing Collections The number of addresses of a natural person who is resident or has a known address is at least one. context NaturalPerson inv: self.address -> select(naturalperson.inhabitant.attrstate = #resident or naturalperson.inhabitant.attrstate = #known) -> size > 0 10
Visualizing Collections context NaturalPerson inv: self.address -> select(naturalperson.inhabitant.attrstate = #resident or naturalperson.inhabitant.attrstate = #known) -> size > 0 /self: NaturalPerson a: a: Address Address a : Inhabitant #n attrstate attrstate = #resident #resident #known #known n > 0 shortcut for select: a - iterator, n - result shortcut: set boxes for collections 11
Visualized Logical Expressions The citizenships of a person are different. context NaturalPerson inv: self. citizenship -> forall(x,y: state x.attrcitizenship = y.attrcitizenship implies x = y) shortcut: implies inv: uniquecitizenship /self: NaturalPerson /self : NaturalPerson isin / x: State attrcitizenship = a : State isin / y: State attrcitizenship = b a = b implies / x: State = / y: State shortcut: forall 12
Visualized Logical Expressions The birth date of a mother has to preceed the birth date of her child. context NaturalPersoninv: (self. naturalpersoncare.attrkind = #mother) implies self.birth.attrbirthdate < self. naturalpersoncare.statuoryagent.birth.attrbirthdate 13
inv /self: NaturalPerson /ID: NaturalPersonCare attrkind = #mother id /self: NaturalPerson implies id /ID: NaturalPersonCare attrkind = #mother : Birth attrbirthdate = y statutoryagent : NaturalPerson x > y : Birth attrbirthdate = x 14
Visualized Logical Expressions Disjunction and Conjunction: ((A and B) or C) and D A B C D and or idea for shortcuts: Peircean graphs and 15
Composed Constraints Natural persons without the state of inhabitant don t have an address AND the citizenships of a person are different. inv reference subdiagram content unknownaddress inv: unknownaddress uniquecitizenship inv: uniquecitizenship 16
Related Work Constraint diagrams: Kent et.al. NaturalPerson address Address inv : Address Birth birth attrdateofmovein Date /self: NaturalPerson birth : Birth attrdateofmovein = x attrbirthdate x y attrbirthdate = y y < x 20
Related work Constraint diagrams: Kent et.al. visualization is not based on UML notation partly visualizes OCL formally defined, tool support OCL meta modelling: Richters, Gogolla validation of OCL constraints in snapshots tool support Formal semantics for OCL denotational semantics based on graph transformation 21
Conclusions visualization of OCL based on collaborations limited amount of new core notations variety of visual shortcuts adaption of OCL metamodel stronger integration of the OCL and UML meta models along collaborations future work mapping between textual and visual notations after consolidation of OCL meta model visual editor for proposed OCL notation 22