Domain-Specific Modeling (And the Eclipse Modeling Framework)
Total Page:16
File Type:pdf, Size:1020Kb
Domain-specific modeling (and the Eclipse Modeling Framework) Ákos Horváth Gábor Bergmann Dániel Varró István Ráth Model Driven Software Development Lecture 2 Budapesti Műszaki és Gazdaságtudományi Egyetem Méréstechnika és Információs Rendszerek TanszékMetamodeling and Domain Specific Modeling METAMODELS, INSTANCE MODELS Metamodeling and Domain Specific Modeling Metamodel: Specify Concepts an Appl. Domain Automaton § Metamodel: o Precise specification of transitions initial states domain concepts of a CompState State from Transition modeling language kind:StateEnum to § Goal: to define... Metamodel o Basic concepts o Relations between concepts t3 fr to o Attributes of concepts ini Abstraction / refinement st st o s1 a1 s3 (Taxonomy, Ontology) tr tr fr st to between model elements t1 s2 t2 o Aggregation to fr o Multiplicity restrictions Instance model o ... Metamodels and instance models Reference / Automaton refine Aggregation Association 1..* transitions initial states Multiplicity 1 * Class CompState State from Transition kind:StateEnum Generalization to Attribute Metamodel level Object Metamodel Model level t3 fr to a1 s3 Role ini t3 st st s1 a1 s3 s1 t2 tr tr fr st to t1 s2 t1 s2 t2 to fr Abstract syntax Concrete syntax Type conformance /Instantiation /Classification Automaton § Each model element is refine an instance of (conforms to) transitions initial states a metamodel element CompState State from Transition § kind:StateEnum Direct type: to o No other type exists «instanceOf»… … lower in the type hierarchy o s1 à CompState t3 fr to ini st st § Indirect type: s1 a1 s3 tr tr o Superclass of the direct type fr st to à t1 s2 t2 o s1 State to fr Classification vs. Generalization 1. Fido is a Poodle ü 1+2 = Fido is a Dog 2. A Poodle is a Dog ü 1+2+3 = Fido is an Animal 3. Dogs are Animals ! 1+4 = Fido is a Breed 4. A Poodle is a Breed ! 2+5 = A Poodle is a Species 5. A Dog is a Species § Generalization (SupertypeOf) is transitive § Classification (InstanceOf) is NOT transitive Type conformance of references Metamodel § A link in a model is from State Transition type conformant if to o type(src(link)) is subtype of src(type(link)) CompState «instance» o type(trg(link)) is subtype of «instance» trg(type(link)) o Informally: «instance» • The type of the source object is a subtype of the source s1:CompState t1:Transition class of the link’s type. :from Model • The type of the target object is a subtype of the target class of the link’s type. Can you define generalization for references? Containment hierarchy § Each model element has a a1 unique parent s1 o N children à 1 parent a21 a22 o Single root element s211 s221 § Aggregation as relationship: o Defined in the metamodel along reference edges Metamodel Automaton o Provides restriction for a1 refine instance models § Circularity s1 states CompState State o No circular containment (in the model) a21 a22 o Aggregation relations in the metamodel may be circular s211 s221 (hierarchy) Multiplicity restrictions § Definition: Lower bound .. Upper bound o Lower bound: 0, 1, (non-negative integer) o Upper bound: 1, 2, … * (positive integer + any) § Scope: o References: allowed number of links between objects of specific types o Attributes: e.g. arrays of strings (built-in values) Team Which are the most 1 members common multiplicity 0..* definitions in practice? captain Player 0..1 Derived Features § A derived feature can be calculated from others o Usage: helpers for designers / tools o It need not be persisted o Automatic updates pets Person Animal § Derived attributes: age = currYear – birth /dogs § Derived references: Dog Cat dogs = -- pets --> Dog § Derived objects: knows Mike knows /member „Gang”: /member o Sam /g:Gang everyone knows everyone /member Peter knows DOMAIN-SPECIFIC MODELING Metamodeling and Domain Specific Modeling Example metamodel Metamodeling and Domain Specific Modeling Instance model, abstract syntax Metamodeling and Domain Specific Modeling Instance model, concrete syntax Metamodeling and Domain Specific Modeling Domain specific modeling languages Business System analyst designer Business process Dependability Security expert expert Dependability model Risk model Software Software developer architect Programming language Software model Metamodeling and Domain Specific Modeling Usage example of DSMs Concrete syntax Abstract syntax Well-formedness constraints Behavioural semantics, simulation, refactoring Call graph (view) State machines (different DSM) Metamodeling and Domain Specific Modeling Structure of DSMs Graphical syntax Abstract syntax Well-formedness constraints Behavioural semantics, simulation, refactoring Mapping Code generation View Code (documentation, Textual syntax configuration) Metamodeling and Domain Specific Modeling Aspects of Defining DSMLs Abstract syntax Well- Collaborate formedness constraints DSML Views Concrete translations syntax mappings Behavioural (dynamic) semantics Metamodeling and Domain Specific Modeling Designing modeling languages § Language design checklist o Abstract syntax (metamodel) • Taxonomy and relationships of model elements • Well-formedness rules o Semantics (does not strictly belong to a language) • Static • Behavioural o ??? o Concrete syntax • Textual notation • Visual notation Metamodeling and Domain Specific Modeling Revisiting the example Automaton Generalization transitions Association initial states from AccState State Transition Class Instantiation color:{R,G,B} to Attribute Meta (Language) level Metamodel (Instance) Model level t3 fr to Object ini st st s1 a1 s3 tr tr fr st to t1 s2 t2 Link to fr Model in abstract syntax Metamodeling and Domain Specific Modeling Revisiting the example Automaton transitions initial states AccState State from Transition color:{R,G,B} to Meta (Language) level Metamodel Model level t3 fr to a1 s3 ini t3 st st s1 a1 s3 s1 t2 tr tr fr st to t1 s2 t1 s2 t2 to fr Abstract syntax Concrete syntax Metamodeling and Domain Specific Modeling Example: Concrete Syntax request() { if (state == "idle" && this.load<10) state = "calculating"; } response() { if (state == "calculating") state = "idle" } Graphical notation Textual notation Metamodeling and Domain Specific Modeling Textual vs. Visual § Textual notation: + Easy to write: Able to capture complex expressions - Difficult to read: Difficult to comprehend and manage after certain complexity (e.g what refers me?) § Visual notation: + Easy to read: Able to express (selected / subset of) details in an intuitive, understandable form + Safe to write: Able to construct syntactically correct models - Difficult to write: graphical editing is slower Metamodeling and Domain Specific Modeling Example: UML model <?xml version="1.0" encoding="UTF-8"?> <uml:Package name="geography" xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_7qi_AS2uEd-VCP9iY9GYHg"> [...] <packagedElement xmi:type="uml:Class" name="Country" xmi:id <ownedAttribute name="name" aggregation="composite" xmi: <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/ </ownedAttribute> <ownedAttribute name="formerCapitals" aggregation="composite <upperValue value="*" xmi:type="uml:LiteralUnlimitedNatural <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_yl- </ownedAttribute> <ownedOperation name="coup" xmi:id="_fHicEC2vEd-VCP9iY9GYHg"> <ownedParameter direction="return" xmi:id="_le7b8C2vEd </ownedOperation> </packagedElement> <packagedElement xmi:type="uml:Class" name="City" xmi:id="__KgpUC2vEd <ownedAttribute name="name" aggregation="composite" xmi: <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/ </ownedAttribute> <ownedAttribute name="founded" aggregation="composite" xmi:id <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/ </ownedAttribute> </packagedElement> <packagedElement xmi:type="uml:Association" xmi:id="_Xq_8kC2wEd <ownedEnd name="cities" type="__KgpUC2vEd-VCP9iY9GYHg" xmi <upperValue value="*" xmi:type="uml:LiteralUnlimitedNatural <lowerValue value="1" xmi:type="uml:LiteralInteger" xmi Abstract Syntax Graphical notation</ownedEnd> Textual notation <ownedEnd name="country" type="_GgAssC2vEd-VCP9iY9GYHg" (Class Diagram) <upperValue xmi:type(XMI="uml: LiteralUnlimitedNatural2.1) " xmi <lowerValue xmi:type="uml:LiteralInteger" value="1" xmi </ownedEnd> Metamodeling and Domain</packagedElement Specific Modeling> </uml:Package> Multiplicity of Notations § One-to-many o 1 abstract syntax à many textual and visual notations • Human-readable-writable textual or visual syntax • Textual syntax for exchange or storage (typically XML) • In case of UML, each diagram is only a partial view o 1 abstract model à many concrete forms in 1 syntax! • Whitespace, diagram layout • Comments • Syntactic sugar o 1 semantic interpretation à many abstract models • e.g. UML2 Attribute vs. one-way Association Metamodeling and Domain Specific Modeling METALEVELS Metamodeling and Domain Specific Modeling Exercise Metalevels § Nodes o Film, Human, Novel, Psycho (film), Book, Man, Thriller, Work of Art, The Bourne Identity (novel), Genre, Robert Ludlum, Sir Alfred Hitchcock, this book here: Demonstrated by the exercise: • Instantiation vs. subtyping • Edge subtyping • Metalevels • Multi-level metamodeling • Deep instantiation § Edges o written by, directed by, creator, subtype, instance Metamodeling and Domain Specific Modeling Metalevels Automaton transitions initial states AccState State from Transition „Meta” relationship color:{R,G,B} to between models «instance» … … t3 fr to ini