Presentation is loading. Please wait.

Presentation is loading. Please wait.

Composition of UML Described Refactoring Rules Presented by Chin-Yi Tsai.

Similar presentations


Presentation on theme: "Composition of UML Described Refactoring Rules Presented by Chin-Yi Tsai."— Presentation transcript:

1 Composition of UML Described Refactoring Rules Presented by Chin-Yi Tsai

2 2 Outline Introduction Introduction Refactoring Refactoring Composition of Refactorings Composition of Refactorings Related Work Related Work Conclusion Conclusion

3 3 Introduction Refactoring can be seen as a process of improving structure of a software without changing its behavior. Refactoring can be seen as a process of improving structure of a software without changing its behavior. From W.F. Opdyke, “ Refactoring: A Program Restructuring Aid in Designing Object-Oriented Application Frameworks, ” PhD thesis, Univ. of Illinois at Urbana-Champaign, 1992. From W.F. Opdyke, “ Refactoring: A Program Restructuring Aid in Designing Object-Oriented Application Frameworks, ” PhD thesis, Univ. of Illinois at Urbana-Champaign, 1992. As corner stone for XP and agile process As corner stone for XP and agile process The refactoring process: The refactoring process: Identify where the software should be refactored Identify where the software should be refactored Which refactoring Which refactoring Guarantee that the applied refactoring perserves behavior Guarantee that the applied refactoring perserves behavior Apply the refactoring Apply the refactoring Assess the effect of the refactoring on quality Assess the effect of the refactoring on quality Maintain the consistency Maintain the consistency Refactoring techniques: Refactoring techniques: Assertions (preconditions, postconditions, and invariants) Assertions (preconditions, postconditions, and invariants) Graph transformation Graph transformation Model transformation (MDA) At the same level of abstraction Instances of the same meta-model

4 4 Introduction (cont ’ d) Use OCL and UML metamodel to define rules for refactoring UML model. Use OCL and UML metamodel to define rules for refactoring UML model. To check if a sequence of transformation is successfully applicable for a given mode before the transformations are executed on it. To check if a sequence of transformation is successfully applicable for a given mode before the transformations are executed on it.

5 5 Refactoring The behavior preservation is assured by so called “ preconditions ” and “ postconditions ”. The behavior preservation is assured by so called “ preconditions ” and “ postconditions ”. OCL constraints can be used to describe these pre and postconditions. OCL constraints can be used to describe these pre and postconditions. Refactoting Refactoting Code Code UML model UML model Database schemas Database schemas Software architecture Software architecture Software requirements Software requirements

6 6 Description of the “ Abstraction ” Transformation Instances of metamodel elements

7 7 context Package def: 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) and not classes->exists(name= absProduct) not interfaces->exists(name= absProduct) post: let: absProd:Class=classes->select(name=absProduct)->any(true) in let: gen:Generalization=generalizations->select(g|g.specific.name= product and g.general.name= absProduct)->any(true) in absProd.isAbstract=true and absProd.oclIsNew() and gen.oclIsNew()

8 8 Description of the “ Interface Extraction ” Transformation

9 9 context Package def: implementations:Set(Interfaces::Implementation)= self.ownedClassifier->collect(implementation) context Package::interfaceExtraction (creator:String, creatorInf:String) pre: classes->exists(name= creator) and not classes-> exists(name= creatorInf) and not interfaces-> exists(name= creatorInf) post: let: creatInf:Interface=interfaces->select(name=creatorInf)->any(true) in let: imp:Implementation=implemenations-> select(i:Implementation|i.ilementatingClassifier.name= creator and i.contract.name= creatorInf)->any(true) in let: creat:Class=classes->select(name=creator)->any(true) in creatInf.oclIsNew() and imp.oclIsNew and creat->collect(operation)->select(visibility=VisibilityKind::public)-> forAll(o1:Operation|creatInf->collect(operation)-> exists(o2:Operation|o2.hasSameSignature(o1))) and creatInf->collect(operation)->forAll(c:Operation| c.oclIsNew())

10 10 Composition of Refactorings The composition of refactorings would allow users of the tool to create their own complex refactorings that fullfill their specific needs. The composition of refactorings would allow users of the tool to create their own complex refactorings that fullfill their specific needs. It is easier to analyze composed refactorings if they are represented by one pre-post pair. It is easier to analyze composed refactorings if they are represented by one pre-post pair.

11 11

12 12 Calculate the composite precondition Calculate the composite postcondition

13 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 14 Example1

15 15 Example2

16 16 Example3

17 17

18 18 Example of a Composed Refactoring Rule context Package::composed (product:String, absProduct:String, creator:String, creatorInf:String) pre: classes->exists(name= product) and not classes->exists(name= absProduct) and not interfaces-> exists(name= absProduct) classes->exists(name= creator) and not classes-> exists(name= creatorInf) and not interfaces-> exists(name= creatorInf) and not absProduct=creatorInf

19 19 Example of a Composed Refactoring Rule post: let: absProd:Class=classes->select(name=absProduct)->any(true) in let: gen:Generalization=generalizations->select(g|g.specific.name= product and g.general.name= absProduct)->any(true) in let: creatInf:Interface=interfaces->select(name=creatorInf)->any(true) in let: imp:Implementation=implemenations-> select(i:Implementation|i.ilementatingClassifier.name= creator and i.contract.name= creatorInf)->any(true) in let: creat:Class=classes->select(name=creator)->any(true) in absProd.isAbstract=true and absProd.oclIsNew() and gen.oclIsNew() and creatInf.oclIsNew() and imp.oclIsNew and creat->collect(operation)->select(visibility=VisibilityKind::public)-> forAll(o1:Operation|creatInf->collect(operation)-> exists(o2:Operation|o2.hasSameSignature(o1))) and creatInf->collect(operation)->forAll(c:Operation| c.oclIsNew())

20 20

21 21 Related Work Opdyke represents refactorings as combinations of preconditions whose purpose is the preservation of behavior of a program. Opdyke represents refactorings as combinations of preconditions whose purpose is the preservation of behavior of a program. Roberts introduces postconditions into the refactoring process. Roberts introduces postconditions into the refactoring process. Compose refactoring related to design patterns. Compose refactoring related to design patterns. Refactoring: Using OCL expressions applied to the metamodel of UML. Refactoring: Using OCL expressions applied to the metamodel of UML.

22 22 Conclusion To validate the sequence of these transformations and to find the way of composing these transformations in order to get more complicated transformation that can be applied or used in further composition. To validate the sequence of these transformations and to find the way of composing these transformations in order to get more complicated transformation that can be applied or used in further composition. The future steps will involve the creation of a library of mini transformation descriptions in order to get some foundations for describing more complicated refactorings or design pattern. The future steps will involve the creation of a library of mini transformation descriptions in order to get some foundations for describing more complicated refactorings or design pattern.


Download ppt "Composition of UML Described Refactoring Rules Presented by Chin-Yi Tsai."

Similar presentations


Ads by Google