Department of Computer Science, Institute for Software and Multimedia Technology OCL ((OObbjjeecctt CCoonnssttrraaiinntt LLaanngguuaaggee)) by Example DDrr. BBiirrggiitt DDeemmuutthh In theory, there is no difference between theory and practice. But, in practice, there is. Jan L. A. van de Snepscheut/Yogi Bera Dr. Birgit Demuth MINE Summer School, Nida, 2009 2 Main Goals of the Lecture • Bridge the gap between practically used software specifications (UML) and formal languages • IInnttrroodduuccee iinnttoo OOCCLL ((hhiissttoorryy, oouuttlliinnee, lliitteerraattuurree)) • Learn how to specify semantics using OCL • LLeeaarrnn wwhhaatt aarree iinntteerreessttiinngg OOCCLL uussee ccaasseess • Inform what OCL tools can already be used Dr. Birgit Demuth MINE Summer School, Nida, 2009 3 Foundation: Assertions • An assertion is a predicate (i.e., a true–false statement) placed in a program to indicate that the developer thinks tthhatt tthhe preddiicatte iis allways ttrue att tthhatt pllace [[WWiikkiipeddiia]]. • Usagge in – Hoare logic [Hoare 1969] – Design by contract [Meyer 1986, Eiffel] – FFoorr rruunn-ttiimmee cchheecckkiinngg ((JJaavvaa ((assertt)), JJMMLL, JJAASSSS, SSQQLL, …) – During the development cycle (debugging) – Static assertions at compile time Dr. Birgit Demuth MINE Summer School, Nida, 2009 4 Object Constraint • Model-based assertion • [[Warmer andd Klleppe]] ddeffine a constraint as ffollllows: “AA ccoonnssttrraaiinntt iiss aa rreessttrriiccttiioonn oonn oonnee oorr mmoorree vvaalluueess of (part of) an object-oriented model or system.“ • OCL as specification language for object constraints Dr. Birgit Demuth MINE Summer School, Nida, 2009 5 History of OCL • Developed at IBM in 1995 originally as a business engineering language • AAddoopptteedd aass aa ffoorrmmaall ssppeecciiffiiccaattiioonn llaanngguuaaggee wwiitthhiinn UUMMLL • Part of the official OMG standard for UML (from version 1.1 on) • Used for precisely defining the well-formedness rules (WFRs) for UML and further OMG-related metamodels •• CCuurrrreenntt vveerrssiioonn iiss OOCCLL 22.00 Dr. Birgit Demuth MINE Summer School, Nida, 2009 6 OCL (Object Constraint Language) • Extends the Unified Modeling Language (UML) • FFoorrmmaall llaanngguuaaggee ffoorr tthhee ddeeffiinniittiioonn ooff ccoonnssttrraaiinnttss aanndd queries on UML models • Declarative • SSidde effffect ffree • Add precise semantics to visual (UML-) models •• GGeenneerraalliizzeedd ffoorr aallll MMOOFF bbaasseedd mmeettaammooddeellss • Meanwhile generally accepted • Many extensions such as for temporal constraints • „Core Language“ of other OMG languages (QVT, PRR) Dr. Birgit Demuth MINE Summer School, Nida, 2009 7 Literature [[1]] Warmer,, J.,, Kleppppe,, A.: The Objject Constraint Langguagge. Precise Modeling with UML. Addison-Wesley, 1999 [2] Warmer, J., Kleppe, A.: The Object Constraint Language SSeeccoonndd EEddiittiioonn.. Getting Your Models Ready For MDA. Addison-Wesley, 2003 [3] OMG UML specification, wwwwww..oommgg..oorrgg//tteecchhnnoollooggyy//ddooccuummeennttss//mmooddeelliinngg_ssppeecc_ccaattaalloo g.htm#UML [4] OMG UML 2.0 OCL, wwwwww.oommgg.oorrgg//tteecchhnnoollooggyy//ddooccuummeennttss//ffoorrmmaall//ooccll.hhttmm [5] Heinrich Hußmann: Formal Specification of Software Systems. Course, 2000, Technische Universität Dresden Dr. Birgit Demuth MINE Summer School, Nida, 2009 8 Dr. Birgit Demuth MINE Summer School, Nida, 2009 9 Constraint Definition – „A constraint is a restriction on one or more values of (part of) an object-oriented model or ssyysstteemm.“ • A constraint is formulated on the level of classes, but its semantics is applied on the level of objects. • originally formulated in the syntactic context of a UML UUMMLL mmooddeell ((ii.ee. aa sseett ooff UUMMLL ddiiaaggrraammss)) Dr. Birgit Demuth MINE Summer School, Nida, 2009 10
Description: