Welcome!

Welcome to Metamodelrefactoring.org. This website has the purpose to show which kinds of changes could be applied on the metamodel. We’re developing a catalog of changes and we’ll insert figures to depict the metamodel excerpt before and after the refactoring. For clarity the metametamodel used in this context is Ecore(EMF).

This is a sticky post! continue reading?

Push down property

Informal Description

Level? Push down property refactoring takes place on the class level in the project hierarchy.Why? When working on superclasses and their subclasses, it is needed to encapsulate and move behavior or superclass properties to subclasses to avoid complexity  Use A possible scenario is when a developer extracts metaclass from its superclass as creating new object then Push down properties of superclass to subclass in order to encapsulate it more specifically. Working On pushing down property attributes A of superclass C is deleted and moved to subclass C’ of superclass C without changing the type.

Formal Description

  • delete attribute A from superclass C.
  • add attribute A to subclass C’. The attribute type and name are not changed.

 

Granularity

  • Composite: Consists of several operations: deleting attribute, add attribute.

Operation Types

  • Delete: attribute deleted from superclass
  • Add: attribute added to subclass

MetaClasses

  • Class: The Push down property refactored in superclass to subclass.
  • Attribute: Attribute of superclass is deleted then added to subclass.

 

Hierarchy View

In this example we can see how attribute attribute3 with Eint type in superclass rootA after refactoring is pulled up to subclass subA. The type of attribute3 is not changed.

before after

Diagram View

This is ecore diagram representation of example above.

before after

 

Flatten hierarchy

Informal Description

Level? Flattening the hierarchy happens on the class level in the project hierarchy. Why? When working with lots of metaclasses in a complex hierarchical structure it can become quite difficult to maintain. Use A possible scenario would be where a developer has an hierarchy where one of the subclasses is much bigger than the others and no longer resembles its siblings. In this case it might be useful to dismantle the hierarchy. Working On flattening the hierarchy the properties of the superclass are pulled up into all of its children, after which the superclass is deleted.

Formal Description

  • On Flattening the hierarchy of superclass EClass A  in  EPackage P and Eclass A1 and Eclass with EsuperType equal to Eclass A (the children of A):
  • For Each EAttribute T in Eclass A we Push down EAttribute T to Eclass A1 and Eclass An
  • For Each  EReference R in Eclass A we Push down EReference R to Eclass A1 and Eclass An
  • The ESuperType of superclass Eclass A1 and Eclass An will be set to the ESuperType of A.
  • Eclass A is deleted.

 

Granularity

  • Composite: Consists of several operations: Add Attribute, Add Reference, Change SuperType and Delete Class.

Operation Types

  • Add:  Attributes are added, references are added
  • Delete: Deleting a superclass.
  • Change: SuperType of classes are changed.

MetaClasses

  • Class: A Class is deleted.
  • Attribute: Added to the subclasses
  • Reference: Added to the subclasses

 

Hierarchy View

In this example we flatten the hierarchy of Eclass RootA. We can see that the attributes ofEclass RootA have been moved to its children: Eclass subA, Eclass SubA1 andEclass SubA1 now have EAttribute attribute2, EAttribute attribute3 and EAttribute attribute1. Also Eclass RootA  has been removed.

before after

 

Diagram View

In the ecore diagram it is more clearly visible what happens. Eclass RootA has been removed and the 3 EAttributes (attribute1, attribute2 and attribute3) are now in all 3 of the children Eclass (subA1, subA, subA2) .

before after

Restrict metaproperty

Informal Description

Level? restrict metaproperty refactoring takes place on the class level in the project hierarchy.Why? When working with different hierarchy of classes it might be useful to restrict properties of class references to other classes in order to avoid some complexity fo boudning classes Use A possible scenario is when a developer would have to create one to one or one to many connections between classes. This can be done by restricting the multiplicity (in normal case reference has [1 to *] multiplicity) references in selected class. Working On restricting metaproperty of references can be done by changing upper bound and lower bound of reference on its property.

Formal Description

  • On restricting metaproperty of selected class, the lower bound or upper bound of reference property is changed.
  • The reference list of parent class will be automatically updated.

 

Granularity

  • Atomic: Consists of single operation: changing the lower bound and upper bound property of reference in selected class.

Operation Types

  • Change: lower bound and upper bound properties of reference are changed

MetaClasses

  • Class: the multiplicity of reference changes in parental class.
  • Reference: lower bound and upper bound properties of reference are changed.

 

Hierarchy View

In this example we can see how reference EreferenceA with mulitplicity 1..* restricted to 1..n. Then the restriction changed from [1 to undefinded] to [ 1 to defined].

before after

 

Diagram View

This is ecore diagram representation of example above.

before after

 

Change Eclass abstract

Informal Description

Level? Change of class abstract refactoring takes place on the level of properties. Why? During the development process there will be need to have a class which cannot be instantiated. When developer made some changes on modeling and made hierarchy of classes, it is useful to make one or several classes abstract. It can be represented as superclass but it will not be instantiated, hence the encapsulation will be more properly Use A possible scenario is when developer creates EClass then during the modeling makes several child subclasses. Making Eclass as abstract can keep modeling project more encapsulated and EClass will not be instantiated. Working On Changing the Eclass abstract the property inside the Eclass is changed.

Formal Description

  • On changing the abstract variable of Eclass A, the value of the EBoolean abstract inside Eclass A is set to either true or false.

 

Granularity

  • Atomic: Consists of single operation: changing the value of the EBoolean property abstract inside an Eclass.

 

Operation Types

  • Change: An EBoolean property is changed.

 

MetaClasses

  • Class: Only a property inside an EClass property is changed

 

Hierarchy View

In this example we can see how reference the property Abstract of type EBoolean is changed from false to true. This happens in a selected EClass subA.

before after

Diagram View

This is ecore diagram representation of example above. The change is subtle but visible as well in the ecore diagram. Where The name of the Eclass subA is put in italic when it is set to abstract.

before after

Extract superclass

Informal Description

Level? Extract superclass refactoring takes place on the class level in the project hierarchy.Why? When working with lots of metaclasses it might be usefull to extract common features of classes and use them to create a new superclass. This in order to promote re-useability and thus to lower maintenance.  Use A possible scenario is when a developer would have two classes related to seemingly separate concepts for instance a forms and pages. But during development it appears that there are common features. Such as URL’s or input, the developer may decide to create a common superclass with these common attributes. In this example it could be “webObject”. Not that it also possible to derive this from a selection of attributes from one class.  Working On Extracting superclass from a class the attributes are removed from the class and put into a new class. This new class then becomes the parent of the initial class.

Formal Description

  • On Extracting a superclass from  EClass A inside EPackage P, a new EClass A’ will be added to Epackage P.
  • For Each selected EAttribute T in Eclass A we Add EAttribute T to A’ and remove from A.
  • For Each selected  EReference R in Eclass A we Add EReference R to A’ and remove from A.
  • The ESuperType of superclass Eclass A” will be set to the ESuperType of A.
  • The ESuperType of subclass Eclass A will be set to EClass A’.

 

Granularity

  • Composite: Consists of several operations: Adding a metaclass, Add attributes, Delete attribute,  Add references, Delete references.

 

Operation Types

  • Add: A MetaClass is Added, Attributes are added and References are Added.
  • Delete: Deleting references and attributes from the former metaclass.

 

MetaClasses

  • Class: New metaclass added
  • Attribute: Added to the new superclass, removed from subclass
  • Reference: Added to new superclass, removed from subclass

 

Hierarchy View

In this example we extract the superclass from the EAttribute with name “A” of type enumM inside EClass with name subA1. The result is a SuperClass EClass with name SUPER_subA1 with an EAttribute with name A and parent Eclass with name rootA. Eclass SubA1 has parent class Eclass with name Super_subA1.

 

before after

Diagram View

In the ecore diagram it is more clearly visible what happens, we can see that a new parent has been created with the attribute A property that was initially in SubA1.

before after

Change reference type

Informal Description

Level? Changing reference type is operation on the class level in the project hierarchy.Why? The reference has the type that points to another class, by this, it is possible to establish the connection between classes. During the modeling  the type of reference can be changed to another class, Hence the type of reference will be changed. Use A possible scenario would be where the developer decides to change the class behavior, therefore the type of reference will be changed to another class. Working when one changes the reference type; it will be changed on reference properties. the list the reference list of the parent class will be automatically updated.

Formal Description

On changing the reference type T of EClass C, on reference properties will be shown new EType, the another class or its own parent class selected for EType. The reference list of the parent class will be automatically updated.

 

Granularity

  • Atomic: the changing reference type is only one operation type.

Operation Types

  • Change: the reference deleted from parent class

MetaClasses

  • class: the change reference type is inside class metaclass.
  • reference: reference type is changed on reference properties.

 

Hierarchy View

In this example we can see the EReference0 type of class classA were pointed to the subA2 class was changed to class classB.

before after

 

Diagram View

In this ecore diagram example we can see, when reference type is changed from classA class the connection changed to class classB.

before after

Merge references

Informal Description

Level? Merge references is the operation on metamodel level in the project hierarchy Why? At some point developers see themselves working with a lot of different metaclasses. This can be problematic when they are using references which are restricted to metaclasses and it requires changing often. Having the superclass act as another layer of abstraction to simplify this process.Use A possible scenario would be where a developer has two references to WebButton and WebLabel to respectively. Both are children of WebElement. The developer wants to simplify this by merging them into one and using the parent WebElement instead. Working On Merging references two references are replaced by a new one pointing to the mutual parent of the types of the original two references.

Formal Description

On merging EReference R1 and EReference Rn in EClass C:

  • A new EReference R’ is added to Eclass C
  • The property EType of EReference R’ is set to the ESuperType of the Etype of R1 and the Etype of R2
  • EReference R1 and EReference R2 are deleted from EClass C.

 

Granularity

  • Composit: it contains an Add operation which is adding EReference to an Eclass, a Change operation on the Etype of an Ereference and a Delete operation of EReferences.

Operation Types

  • Add: Refactoring has Add type because an EReference is added.
  • Change: Refactoring has Change type because it changed the property of an Ereference
  • Delete: Refactoring has Delete type because EReferences are deleted.

MetaClasses

  • Class: A class is involved because References are removed/added to it
  • Reference: References are involved because they are created/deleted and their EType property is changed.

 

Hierarchy View

In this example we can see how after refactoring references rootAReference1 and rootAReference2 of class rootA were merged as a rootAReference with type to class classC.

before after
   

 

Diagram View

In the given ecore diagram it can be clearly see initial condition of references on class rootA. After merge reference refactoring two references of rootA with types of classA and classB were merged to one reference of type classC.

before after
   

Split reference

Informal Description

Level? Split references is the operation on metamodel level in the project hierarchy Why? When working on superclass that contains one reference to subclasses, splitting reference refactoring can split selected reference of superclass to its subclasses by making the subclasses behavior with superclass more relevant. Use A possible scenario would be when developer has superclass that contains reference with type of subclass. after doing extracting  another metaclasses from subclasses developer can split references of superclass to newly created metaclasses to make their behavior more correctly. Working When reference splitted it will be deleted from its parental class and added new references with types of subclasses.

Formal Description

On splitting EReference R in EClass C:

  • foreach EClass n where the ESuperClass is equal to the Etype property ofEReference R:
  • An EReference Rn is added to Eclass C
  • The property EType of EReference Rn is set to EClass n
  • EReference R is deleted from C

Granularity

  • Composite: It contains several operations; delete reference, add reference.

Operation Types

  • delete: reference deleted from superclass.
  • add: new references added to superclass with types of subclasses.

MetaClasses

  • Class: A class is involved because references created on its parental class.
  • reference: reference deleted and added to superclass.

Hierarchy View

In this example we can see, initially class classC has references classCreference1 and classCreference2 with types of classes. classA and classB. class rootA has reference with type of classC.. After refactoring reference rootAReference of rootA, we will get two references of rootA rootAReference1 and rootAReference2 with types of classes classA and classB.

before after

 

Diagram View

In the given ecore diagram we can clearly see how reference of rootA rootAReference after refactoring were splitted to references with types of classA and classB classes.

before after

 

Delete reference

Informal Description

Level? Deleting reference is operation on the class level in the project hierarchy. Why? During the development process when one class changed or by developer willing the references can be deleted, hence if the reference type shown in different class the connection between two classes will be demolished. It will be useful to make project more encapsulated. Use A possible scenario would be where the developer decides to change the name of class and therefore the representation of object will be changed. Since the class is changed but all attributes and references are saved, in order to clarify the class developer can delete the reference which was pointing another class. Working when one deletes reference; in case if reference pointed to the reference of another class C, the opposite the reference of class C will be empty. In case if reference is pointed to its own class it will be only removed from parental class. and its class reference list will be automatically updated.

Formal Description

On deleting a reference A of EClass C, in case if it was pointed to the reference B of EClass C1, the EOpposite reference B will be empty (EType of B will remain), and reference A will be deleted from parent EClass C, hence the reference list of EClass will be automatically updated.

 

Granularity

  • Atomic: the deleting reference is only one operation type.

Operation Types

  • Delete: the reference deleted from parent class

MetaClasses

  • class: the delete operation is inside class metaclass.
  • reference: reference deleted from parent metaclass.

Hierarchy View

In this example we can see the EReference0 of class classB3 were pointed to the subA2 class was deleted. After deleting the reference EReference0 will be deleted from its parental class.

before after

 

Diagram View

In this ecore diagram example we can see, when reference deleted from subB3 class the connection between classes is demolished.

before after

Add reference

Informal Description

Level? Adding reference is operation on the class level in the project hierarchy. Why? During the development process it is needed on classes to add references that can be pointed to this class itself or another classes. By doing this, the model can be represented clear with established connections between classes. Use A possible scenario would be where the developer decides to make references between two classes and point them to each other so there will be connection between these two classes, the type of connection can be shown on reference property. Working when one adds reference it will be added to the selected class and made child of this class. It needs to be shown on properties of reference which class is the type of connection. Hence, the opposite reference for this can be shown by pointing to another reference on selected type class.

Formal Description

On adding a reference of EClass C, a newly instantiated EReference E is Created and made Child of Eclass C and automatically added to its eReferences property. It is needed to show the EType of reference by shwoing another EClass C1 and it can be taken references of C1 as aEOpposite of E EType.

Granularity

  • Atomic: the adding reference is only one operation type.

Operation Types

  • add: new reference for metaclass is added.

MetaClasses

  • class: the add operation is inside class metaclass.
  • reference: reference added to the metaclass.

Hierarchy View

In this example we can see that references were added to elementA and elementB classes. from elementA class reference it is shown as 1 to 1 connection to reference of elementB. from elementB to elementA the reference Ereference0 is shown as 1 to 0. On the reference property it is shown for EReference3 EType is elementB, for EReference of elementB is shown elementA. The EOpposite of EReference3 is EReference0 in elementB, EType of EReference0 is EReference3 in elementA.

before after

 

Diagram View

In this ecore diagram example we can see, how one reference points to another reference in different class.

before after