composition of uml described refactoring rules presented by chin-yi tsai
TRANSCRIPT
Composition of UML Composition of UML Described Refactoring Described Refactoring
RulesRules
Presented by Chin-Yi TsaiPresented by Chin-Yi Tsai
2
OutlineOutline
Introduction Introduction
RefactoringRefactoring
Composition of RefactoringsComposition of Refactorings
Related WorkRelated Work
ConclusionConclusion
3
IntroductionIntroduction Refactoring can be seen as a process of improving Refactoring can be seen as a process of improving
structure of a software without changing its behavior.structure of a software without changing its behavior. From W.F. Opdyke, “Refactoring: A Program Restructuring Aid in Designing From W.F. Opdyke, “Refactoring: A Program Restructuring Aid in Designing
Object-Oriented Application Frameworks,” PhD thesis, Univ. of Illinois at Object-Oriented Application Frameworks,” PhD thesis, Univ. of Illinois at Urbana-Champaign, 1992.Urbana-Champaign, 1992.
As corner stone for XP and agile processAs corner stone for XP and agile process
The refactoring process:The refactoring process: Identify where the software should be refactoredIdentify where the software should be refactored Which refactoringWhich refactoring Guarantee that the applied refactoring perserves behaviorGuarantee that the applied refactoring perserves behavior Apply the refactoringApply the refactoring Assess the effect of the refactoring on qualityAssess the effect of the refactoring on quality Maintain the consistencyMaintain the consistency
Refactoring techniques:Refactoring techniques: Assertions (preconditions, postconditions, and Assertions (preconditions, postconditions, and
invariants)invariants) Graph transformationGraph transformation
Model transformation (MDA)At the same level of abstractionInstances of the same meta-model
4
Introduction (cont’d)Introduction (cont’d)
Use OCL and UML metamodel to define Use OCL and UML metamodel to define rules for refactoring UML model.rules for refactoring UML model.
To check if a sequence of transformation is To check if a sequence of transformation is successfully applicable for a given mode successfully applicable for a given mode before the transformations are executed on before the transformations are executed on it.it.
5
RefactoringRefactoring
The behavior preservation is assured by so The behavior preservation is assured by so called “called “preconditionspreconditions” and ” and ““postconditionspostconditions”.”. OCL constraints can be used to describe these OCL constraints can be used to describe these
pre and postconditions.pre and postconditions.
Refactoting Refactoting Code Code UML modelUML model Database schemasDatabase schemas Software architectureSoftware architecture Software requirementsSoftware requirements
6
Description of the “Description of the “AbstractionAbstraction” ” TransformationTransformation
Instances of metamodel elements
7
context Packagedef: classes: Set(Class) =self.ownedClassifier->select(oclIsTypeOf(Class))->collect(c|c.oclAsType(Class))def: generalizations: Set(Generalization)=self.ownedClassifier->collect(generalization)def: interfaces: Set(Interfaces::Interface)=self.ownedClassifier->select(oclIsTypeOf(Interfaces::Interface))->collect(c|c.oclAsType(Interfaces::Interface))
context Package::abstraction (product:String, absProduct:String)pre:classes->exists(name= product) andnot classes->exists(name= absProduct)not interfaces->exists(name= absProduct)
post:let: absProd:Class=classes->select(name=absProduct)->any(true) inlet: gen:Generalization=generalizations->select(g|g.specific.name= productand g.general.name= absProduct)->any(true) inabsProd.isAbstract=true andabsProd.oclIsNew() andgen.oclIsNew()
8
Description of the “Description of the “Interface ExtractionInterface Extraction” ” TransformationTransformation
9
context Packagedef: implementations:Set(Interfaces::Implementation)=self.ownedClassifier->collect(implementation)
context Package::interfaceExtraction (creator:String, creatorInf:String)pre:classes->exists(name= creator) andnot classes-> exists(name= creatorInf) andnot interfaces-> exists(name= creatorInf)
post:let: creatInf:Interface=interfaces->select(name=creatorInf)->any(true) inlet: imp:Implementation=implemenations->select(i:Implementation|i.ilementatingClassifier.name= creator andi.contract.name= creatorInf)->any(true) inlet: creat:Class=classes->select(name=creator)->any(true) in
creatInf.oclIsNew() andimp.oclIsNew andcreat->collect(operation)->select(visibility=VisibilityKind::public)->forAll(o1:Operation|creatInf->collect(operation)->exists(o2:Operation|o2.hasSameSignature(o1))) andcreatInf->collect(operation)->forAll(c:Operation| c.oclIsNew())
10
Composition of RefactoringsComposition of Refactorings
The composition of refactorings would allow users of The composition of refactorings would allow users of the tool to create their own complex refactorings that the tool to create their own complex refactorings that fullfill their specific needs.fullfill their specific needs.
It is easier to analyze composed refactorings if they It is easier to analyze composed refactorings if they are represented by one pre-post pair.are represented by one pre-post pair.
11
12
Calculate the composite precondition
Calculate the composite postcondition
13
The first condition for our chain of refactorings to be legal is that every precondition must evaluate to true on its own system state.
The second condition that must be satisfied is that if the postcondition of the first transformation description evaluates to true then the precondition of the second transformation description must also evaluate to true:
14
Example1Example1
15
Example2Example2
16
Example3Example3
17
18
Example of a Composed Refactoring Example of a Composed Refactoring RuleRule
context Package::composed (product:String, absProduct:String, creator:String,creatorInf:String)pre:classes->exists(name= product) andnot classes->exists(name= absProduct) andnot interfaces-> exists(name= absProduct)classes->exists(name= creator) andnot classes-> exists(name= creatorInf) andnot interfaces-> exists(name= creatorInf) andnot absProduct=creatorInf
19
Example of a Composed Refactoring Example of a Composed Refactoring RuleRule
post:let: absProd:Class=classes->select(name=absProduct)->any(true) inlet: gen:Generalization=generalizations->select(g|g.specific.name= productand g.general.name= absProduct)->any(true) inlet: creatInf:Interface=interfaces->select(name=creatorInf)->any(true) inlet: imp:Implementation=implemenations->select(i:Implementation|i.ilementatingClassifier.name= creator andi.contract.name= creatorInf)->any(true) inlet: creat:Class=classes->select(name=creator)->any(true) inabsProd.isAbstract=true andabsProd.oclIsNew() andgen.oclIsNew() andcreatInf.oclIsNew() andimp.oclIsNew andcreat->collect(operation)->select(visibility=VisibilityKind::public)->forAll(o1:Operation|creatInf->collect(operation)->exists(o2:Operation|o2.hasSameSignature(o1))) andcreatInf->collect(operation)->forAll(c:Operation| c.oclIsNew())
20
21
Related WorkRelated Work
Opdyke represents refactorings as Opdyke represents refactorings as combinations of preconditions whose purpose combinations of preconditions whose purpose is the preservation of behavior of a program.is the preservation of behavior of a program.
Roberts introduces postconditions into the Roberts introduces postconditions into the refactoring process.refactoring process.
Compose refactoring related to design Compose refactoring related to design patterns.patterns.
Refactoring: Using OCL expressions applied Refactoring: Using OCL expressions applied to the metamodel of UML.to the metamodel of UML.
22
ConclusionConclusion
To validate the sequence of these To validate the sequence of these transformations and to find the way of transformations and to find the way of composing these transformations in order to composing these transformations in order to get more complicated transformation that get more complicated transformation that can be applied or used in further can be applied or used in further composition.composition.
The future steps will involve the creation of The future steps will involve the creation of a library of mini transformation descriptions a library of mini transformation descriptions in order to get some foundations for in order to get some foundations for describing more complicated refactorings or describing more complicated refactorings or design pattern.design pattern.