A REFACTORING TOOL FOR DESIGN PATTERNS
WITH MODEL TRANSFORMATIONS
Zekai DemirezenYasemin Topaloğlu
Ege UniversityDepartment of Computer Engineering
[email protected]@ege.edu.tr
2/23NWUML06, 12 June 2006
Agenda• Background
– Design Pattern: A Target for Refactoring– Pattern Specification and Metamodeling– Transformation MetaModels– XML Metadata Interchange
• Tool Architecture– Components of the tool– Transformations
• Case Study: Observer Design Pattern– Example MetaModels and Models– Screen Shots
• Conclusions
3/23NWUML06, 12 June 2006
OTHER INPUTS ????
Design Pattern: A Target for Refactoring
Design Model Design Model with design patterns
4/23NWUML06, 12 June 2006
+Applicant()+ApplicantInfo()+MakeApplication()
-companyName : CString-experience : CString-reference1 : CString-reference2 : CString-reference3 : CString
Applicant
+Person()+PersonInfo()
-personID : unsigned long-surname : CString-givenName : CString-middleInitial : char-streetAddress : CString-postCode : CString-countryname : CString-eMailAddress : CString
Person
-is taught by
1
-teaches
0..*+CourseSession()+CourseSessionInfo()
-courseSessionID : unsigned long-courseDate : unsigned long-courseID : unsigned long-courseLocation : CString
CourseSession
+AppStatus()+AppStatusInfo()
-statusCode : char-statusName : CString
AppStatus
+CourseRegistration()+CourseRegistrationInfo()
-registrationDate : unsigned long-completionFlag : bool-confirmedDate : unsigned long
CourseRegistration
+Test()+TestInfo()
-testScore : unsigned long
Test
+Application()+ApplicationInfo()
-productNr : unsigned long-certificationLevel : unsigned long-applicationDate : unsigned long
Application
+PermittedStatusChange()+StatusChangeInfo()
-fromStatus : char-toStatus : char
PermittedStatusChange
+ExamSession()+ExamSessionInfo()
-examSession : unsigned long-examlocation : CString-examDate : unsigned long
ExamSession
-gives0..*
-is achieved1
-is made by
1
-makes
0..*
-allows change in
0..*
-has a
1..*
-is taken by1
-takes0..*
-is made by a1
-made a1..*
-is in1
-is filled by0..*
-uses
1
-is used in
0..*
-applies to a0..*
-is for a1
+Exam()+ExamInfo()
-examID : unsigned long-certificationLevel : unsigned long
Exam
+Employee()+GetCurrentAge()+EmployeeInfo()
-jobType : CString-roomNr : unsigned long-department : CString-division : CString-jobTitle : CString-manager : unsigned long-headsDept : CString-headsDivision : CString-mobileNr : CString-birthDate : unsigned long
Employee
+registrationform()
RegistrationForm
-uses**
ApplicantApplicantList PersonList
findApplicant()
ApplicationRegForm
Applicant()
findPerson()
addPerson()
addApplication()
Application()
MakeApplication()
ApplicationList
"from human-readable ……………………to computer-understandable"
Pattern Specification
5/23NWUML06, 12 June 2006
Role-Based Meta-Modelling• In order to process models in transformation activities, meta-
modeling is required. Meta-modeling defines the rules and the structures of models. Role-based meta-modeling technique is proposed by (France et al,2004) for design pattern meta-modeling.
•Structural Pattern Specification (SPS)
•Interaction Pattern Specification (IPS)
•State Machine Pattern Specification (SMPS)
6/23NWUML06, 12 June 2006
OMG 4 Layer Architecture
What we wantto transform
7/23NWUML06, 12 June 2006
Transformation Meta-Models• Source Meta-Model defines the models that the transformation will be
applied.• Transformation Meta-Model defines the transformation rules and the
steps.• Target Meta-Model defines the output model of the transformation
activity.
Model bModel a
instanceOf
Source Meta-Model
instanceOf
Definition of transformation T: A->B
An application of transformation T(a) = b
instanceOf
Target Meta-Model
8/23NWUML06, 12 June 2006
Tool Inputs
Design Model Design Model with design patterns
Source MetaModel Target MetaModel
Transformation MetaModel
9/23NWUML06, 12 June 2006
XML Metadata Interchange(XMI)XMI is a widely used interchange format for sharing objects using XML.
10/23NWUML06, 12 June 2006
Tool Architecture• Model editor is a standard modeling tool such as Rational Rose that can be
used to prepare the application design models. • Rule editor is used to prepare the source and the target meta-models • Transformation Preparer takes the application model and the source and
the target meta-models as inputs and then matches the application model elements with the meta-elements.
• Transformation machine executes the transformation steps defined in transformation meta-model
Tool Architecture (A. Wagner, 2002)
11/23NWUML06, 12 June 2006
Subcomponents of the Tool• Representation Transformer (RT): It transforms the meta-model’s
XMI representation to object representations by transforming • Transformation Pattern Generator (TPG): This component
produces transformation meta-model at run-time by analyzing structural differences between the source and target meta-models
• Rol-ModelElement Transformer (REM): This component matches the roles with application model elements. Matching activity is a kind of searching process of role’s structural properties in the application model.
• Transformation Machine(TM): It is the last component that executes the transformation meta-model tasks on the application model. Add, delete and update operations assign the role properties in to the selected model elements
12/23NWUML06, 12 June 2006
Transformations-1• XML Representation-Object Representation
Transformation: The source, target and the application models in XMI are transformed into the objects representations.
•Composite Transformation •Transformation Reuse is defined in Appukuttan et al 2003
13/23NWUML06, 12 June 2006
• MetaModel-Model Transformation: The roles constituting the target meta-model are matched with the application model elements and the source meta-model-source model transformation is the result of this matching
Transformations-2
14/23NWUML06, 12 June 2006
• Application Model-Result Application Model Transformation: Model elements in the application model are transformed into the model elements of the target model by processing the steps in the transformation model. Transformation specifications in the transformation machine are applied on the
application model in this transformation.
Transformations-3
15/23NWUML06, 12 June 2006
• Result Application Model Object Representation-XMI Representation Transformation: This step transforms the result model of the transformation process into the XMI format. Each model element is transformed into the
corresponding element in the XMI format
Transformations-4
16/23NWUML06, 12 June 2006
Overview
17/23NWUML06, 12 June 2006
Case Study• We demonstrate the usage of our tool for
the Observer [Gamma et al.] pattern.
• Observer pattern describes the situation in which a one-to-many dependency between objects is present.
• In this case, when one object changes state, all its dependents are notified and updated automatically
18/23NWUML06, 12 June 2006
Case Study:Source Meta-Model• Preparing the Observer Source MetaModel Specification
• Applicability and motivation sections of the patterns in the catalogue are problem definitions for patterns
• In some parts we use stereotypes in order to provide problem semantics. During stereotype usage, we prefer to use universal standard stereotypes.
19/23NWUML06, 12 June 2006
Case Study:Target Meta-Model• Preparing Observer Target MetaModel Specification
• The target specification is the solution of the design pattern. We use the Class structure and the Participants sections of the GOF Design Pattern catalogue to derive this specification.
• Semantic parts of the design pattern target specification are supported by the stereotype usage.
20/23NWUML06, 12 June 2006
Case Study: Application of the ToolAfter the rule definition activities, tool is executed for transformation with the application
model.
21/23NWUML06, 12 June 2006
Case Study: Transformation ModelTPG Component takes these
two models and prepares transformation model with using
• Add• Delete• Update • Unchanged labels.
22/23NWUML06, 12 June 2006
Case Study:Screen Shots
23/23NWUML06, 12 June 2006
Conclusions• We introduced a transformation tool that
performs horizontal transformations for design pattern refactorings on design models.
• Since XMI is not a query language, we could not generate complex definitions of the source model.
• However, our approach in the implementation of the tool does not require to define transformation meta rules which simplifies the transformation implementation.