IBM Software Group A Metamodeling Approach to Pattern Specification Maged Elaasar 1,2, Dr. Lionel...

download IBM Software Group A Metamodeling Approach to Pattern Specification Maged Elaasar 1,2, Dr. Lionel Briand 1, Dr. Yvan Labiche 1 1 Carleton University,

If you can't read please download the document

description

IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Pattern Specification and Detection in the Literature  Mathematical Approaches  Specify a pattern using a mathematical notation (logic)  Convert M1 model into the same mathematical notation  Solve the system and map result back to model  Highlights :  need mathematics skills  integration issues with CASE tools  Metamodeling Approaches  Specify a pattern as an M2 model  Use specification to guide a detection algorithm in navigating the M1 model  Highlights:  have high coupling with UML  lack scalability and complexity management features  specify M2 patterns using M1 constructs  unfamiliar architecture and notation

Transcript of IBM Software Group A Metamodeling Approach to Pattern Specification Maged Elaasar 1,2, Dr. Lionel...

IBM Software Group A Metamodeling Approach to Pattern Specification Maged Elaasar 1,2, Dr. Lionel Briand 1, Dr. Yvan Labiche 1 1 Carleton University, Ottawa, 2 IBM Rational Ottawa Lab MoDELS 2006, Genova, Italy IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, The Need for Model Pattern Specification & Detection Following MDA means models are first class artifacts Model analysis ensures quality of models Various techniques of model analysis are researched Structural Analysis: Architectural Discovery, Anti-Pattern Detection Consistency and Completeness Analysis A common requirement to those analysis techniques is finding patterns Patterns are recurring structures that are either desirable or undesirable Patterns need to be specified before being detected detected in IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Pattern Specification and Detection in the Literature Mathematical Approaches Specify a pattern using a mathematical notation (logic) Convert M1 model into the same mathematical notation Solve the system and map result back to model Highlights : need mathematics skills integration issues with CASE tools Metamodeling Approaches Specify a pattern as an M2 model Use specification to guide a detection algorithm in navigating the M1 model Highlights: have high coupling with UML lack scalability and complexity management features specify M2 patterns using M1 constructs unfamiliar architecture and notation IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Objectives for Pattern Specification and Detection Methodology Patterns are specified as a model using a modeling process Patterns are specified for any (MOF-based) language Specification is concise, precise and scalable Specifications is used to derive detection algorithms Specifications semantics allows for configuring detection algorithm Tooling A visual pattern specification editor A code generator for detection algorithms A pattern detection environment Specifying a representative set of patterns (e.g. structural, behavioral, anti-patterns) IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, The Metamodeling Architecture MOF is a metamodeling language (M3) Modeling languages are defined as instances of MOF (M2) User models are defined as instances of modeling languages (M1) UML Metamodel UML Metamodel Modeling Languages Instance of UML Metamodel UML Metamodel User Models MOF Instance of M3 - MetametaModel M2 - MetaModel M1 - Model Metamodeling Architecture IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Eclipse Modeling Framework (EMF) We consider a subset of MOF called Essential MOF (EMOF) EMOF has simple class diagram semantics EMF provides an implementation of EMOF: the Ecore metamodel IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Our Solution: Pattern Modeling Framework (PMF) PMF is a new framework for pattern specification and detection PMF provides a pattern specification language called Epattern PMF provides a parallel metamodeling architecture Epattern extends Ecore with pattern specification semantics (M3) Patterns are defined as instances of Epattern (M2) Pattern instances are defined as instances of Patterns (M1) UML Metamodel UML Metamodel Modeling Languages Instance of UML Metamodel UML Metamodel User Models Ecore (EMOF) Instance of UML Metamodel UML Metamodel Patterns Instance of UML Metamodel UML Metamodel Pattern Instances Epattern Instance of extends defined for defined for M3 - MetametaModel M2 - MetaModel M1 - Model EMF Architecture PMF Architecture IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Epattern Metamodel Ecore Metamodel EPattern: a meta-class specifying the context of a pattern ERole: a meta-reference specifying a role played by a pattern participant EConstraint: a boolean meta-operation specifying a pattern well-formedness rule EConnector: an meta-element specifying a relationship between two roles EPort: a meta-reference specifying a composition point for a pattern EAssociation: a meta-class specifying a new derived relationship in pattern metamodel IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Epattern Notation 1/2 IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Epattern Notation 2/2 IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Epattern Modeling Process 1. Understand Pattern Structure 2. Create EPattern 4. Generate Detection Algorithm 5. Run Detection Algorithm 6. Inspect Detection Result 2.1. Add ERoles 2.2. Add EConnectors 2.3. Add EConstraints 2.4. Add EPorts 2.5. Reduce Complexity IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, A pattern example: Composite Pattern IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Understand Pattern Structure > Component CompositeLeaf1Leaf2 - compose (child: Component) Children * InterfaceRealization ClassInterface Property Operation Classifier Composite Pattern Simplified UML2 Meta-Model 1 * - class -ownedOperation type * - ownedAttribute 1 - implementingClassifier 1 - contract * - interfaceRealization IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Create EPattern Add ERoles Add EConnectors Add EConstraints Add EPorts component: Interface realization1: InterfaceRealization [ * ] composite: Class realization2: InterfaceRealizationchildren: Property compose: Operation leaf: Class [ * ] contract implementingClassifier ownedAttribute type ownedOperation compositePort: Class gof.structural.Composite class interfaceRealization implementingClassifier interfaceRealization class self.children.aggregation = Aggregation.Composite and self.children.upperBound = -1 composition self.compose.ownedParameter->size() = 1 and self.compose.ownedParameter->at(1).type = self.component parameter IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Reduce Specification Complexity component: Interface realization1: InterfaceRealization [ * ] composite: Class realization2: InterfaceRealizationchildren: Property compose: Operation leaf: Class [ * ] contract implementingClassifier ownedAttribute type ownedOperation self.compose.ownedParameter->size() = 1 and self.compose.ownedParameter->at(1).type = self.component self.children.aggregation = Aggregation.Composite and self.children.upperBound = -1 compositePort: Class class interfaceRealization implementingClassifier interfaceRealization class composition parameter InterfaceBehavioredClassifier Implementation implementedInterfaceimplementingClassifier ** StructuredClassifierType Composition composingClassifiercomposedType ** gof.structural.Composite 1 IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Reduce Specification Complexity component: Interface composite: Class compose: Operation leaf: Class [ * ] implementedInterface implementingClassifier ownedOperation compositePort: Classclass implementingClassifier composedType implementedInterface composingClassifier self.compose.ownedParameter->size() = 1 and self.compose.ownedParameter->at(1).type = self.component parameter 1 1 InterfaceBehavioredClassifier Implementation implementedInterfaceimplementingClassifier ** StructuredClassifierType Composition composingClassifiercomposedType ** gof.structural.Composite 1 IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Other Ways of Managing Complexity (WIP) Pattern Composition: patterns are composed of smaller patterns Pattern Inheritance: patterns are organized into hierarchies Pattern Refinement: inherited pattern semantics can be redefined Pattern Genericity: patterns are defined as templates SubPattern role1: Classifier SuperPattern role1: Classifier role2: Class SubPattern role1: Class SuperPattern role1: Classifier PatternTemplateInstance role1: Classifier PatternTemplate role1: Classifierrole1.attributes.size() = role1.attributes.size() = 2 inheritancerefinementgenericity BigPattern role2: SmallPattern SmallPattern role1: Operation role1: Class composition role2: Parameter IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Conclusion Motivation Pattern detection is an important technique for model analysis Patterns need to be formally specified before being detected Solution (PMF) Complies with the metamodeling architecture Supports patterns of any EMOF-based language (even cross language patterns) Provides ways to cope with pattern complexity and scalability Provides a visual, systematic specification process Future Work: Well-formedness rules for Epattern Other complexity management features Derivation of a detection algorithm Tooling (editor and algorithm generator) Specify/detect various kinds of patterns IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Thank You IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Reduce Complexity with Composition Singleton class : Class [1..1] ownedAttribute class ownedOperation classPort : Class constructor : Operation [1..1] constructor.name =class.name Constructor parameter : Parameter [0..0] ownedParameter operation instanceAccessor : Operation [1..1] instanceAccessor.visibility VisibilityKind.Private and instanceAccessor.isStatic = true Accessor returnResult : Parameter [1..1] returnResult returnResult.type = class AccessorType instanceProperty : Property [1..1] instanceProperty.visibility = VisinilityKind.Private and instanceProperty.isStatic = true Property instanceProperty.type = class PropertyType IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Singleton instanceProperty : InstanceProperty [1..1] instanceAccessor : InstanceAccessor [1..1] constructor : Constructor [1..1] class : Class [1..1] InstanceProperty property : Property [1..1] ownedAttribute class ownedOperation classPort : Class property.visibility = VisinilityKind.Private and property.isStatic = true and property.type = property.class Signature propertyPort : Property Constructor operation : Operation [1..1] operation.name = operation.class.name Constructor operationPort : Operation parameter : Parameter [0..0] ownedParameter operation InstanceAccessor operation : Operation [1..1] operation.visibility VisibilityKind.Private and operation.isStatic = true Signature operationPort : Operation parameter : Parameter [1..1] returnResult parameter.type = operation.class Type 3. Reduce Complexity with Composition IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Generate Detection Algorithm (Work In Progress) Query Class Execute Method: starts the execution at the attached role Bind Method: checks and binds conforming objects to role Traverse Method: extracts related objects at other end Verify Method: checks the constraint on candidate objects Association Class EPattern EPort ERole EConnector EConstraint EAssociation EAssociationEnd Derive Method: derives the related objects at the other end IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Run Detection Algorithm (Work In Progress) component: Interface composite: Class compose: Operation leaf: Class [ * ] implementedInterface implementingClassifier ownedOperation compositePort: Class CompositePattern class implementingClassifier composedType implementedInterface composingClassifier compose.ownedParameter->size() = 1 and compose.ownedParameter->at(1).isOCLOfKind(component) parameter 1 1 The algorithms control flow will be affected by: The input port to start detection from The order of outgoing connectors from every role The order of constraints attached to every role IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Inspect Detection Result (Work In Progress) CompositeInstance1 - composite= - component = - leaf = - compose = Composite Command Composite - composite: Class - component: Interface - leaf: Class - compose: Operation instanceof IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, name: eType name: eType [lowerBounduperBound] 2 namespace.Name name expression 1 2 eType eOppositeEnd.eType 1 2 IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, :Package :Class :Observer [*] Pattern observedClasses ownedClasses :Package IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Execute Step 1.1 Filter Candidate Elements For Every Port 1.2 Create Empty Pattern Instance 1.3 Call Bind Step For Every Ports Role Pattern Instances 2. Bind Step 2.1 Check Pattern Instance For Bound Role 2.2 Filter Candidate Elements 2.3 Clone Pattern Instance And Bind Role Candidate Elements Pattern Instances Pattern Instance 2.4 Call Verify Steps For Every Constraint 2.5 Call Connect Steps for Every Connector 2.6 Check For Optional Role Candidate Elements IBM Software Group | Rational software 9 th MoDELS Conference, Genoa, Italy, October 1 st, Verify Step 3.1 Check Pattern Instance For Bound Constrained Roles 3.2 Check Constraint On Pattern Instance Boolean Pattern Instance 4. Connect Step 4.1 Get Element From Start Role 4.2 Traverse Connector From Start To End Roles 4.3 Call Bind Step for End Role Pattern Instances Pattern Instance