Refactoring

Refactoring is a technique of improving your modeling efficiency by allowing you to extract part of a project to a higher level of abstraction so that other (projects) can get the common part(s) included without the need of re-definition. Let's say, for example, you are modeling a vehicle maintenance company. You have created two projects for the distinct parts of the business - Car washing and car repair. When modeling car washing with class diagram, you have found that classes like Car and Manufacturer are also needed by the car repair model. You then refactor them to a referenced project so that the car repair model can link with it and have the classes included.

What is refactoring?
What is refactoring?

Refactoring not only reduce the time you need to spend by redefining same project data among projects. It also guarantees the correctness of model definition by enforcing common project data to be defined just once. This is also, in fact, the benefit of using project referencing.

How to refactor?

You can refactor model element(s) or a diagram along with its contained element to referenced project. No matter which way you take, make sure project referencing was established. If you are unclear about project referencing, please read the previous chapters.

Refactor model elements

  1. Open the Model Explorer.
    Open Model Explorer
    Open Model Explorer
  2. Select and right click on the model elements you want to refactor to referenced project. Select Refactor to Referenced Project... from the popup menu.
    Refactor classes
    Refactor classes
  3. You are prompted for saving project. Click Yes. If you click No, refactor will stop.
  4. If the Include Related Diagrams window appears, this means that one or more of the selected elements has been visualized in at least one diagram (as listed on the left of window) with master view created.

    Here you may take any of the following actions to continue.
    • Include the diagrams - Click Include Diagram(s) at the bottom right corner. This will move not only the model elements, but also the diagrams listed on the left hand side of window to the referenced project. Since the action is not undoable, think carefully before continuing.
    • Remove the master views - Click Stop Refactor at the bottom left corner. Open the diagrams where the master views of the selected model elements exist. Delete them. When delete, make sure you are deleting the VIEW instead of model element. Once all master views are removed, re-run step 1.
      Delete only views of element, not model elements
      Delete only views of element, not model elements
  5. Refactor not only moves the selected elements to referenced project, but also those related elements. Here are two examples:
    • Connectors that connect between the selected elements.
    • Class being selected as type of attribute of selected class.
    If such related elements exist, you will be listed with those elements. Check them. If you accept moving them to referenced project, click Continue at the bottom right corner to continue. Otherwise, click Stop Refactor at bottom left corner to terminate the refactoring.
    Elements to refactor (including those related elements)
    Elements to refactor (including those related elements)
  6. Once the refactoring is complete, the project will reopen itself. From now on, you can access and use the refactored elements through the Model Explorer. Select the referenced project under the drop down menu. Drag to diagram the element(s) to use.
    To re-use referenced classes on current project
    To re-use referenced classes on current project
    Note that auxiliary views of refactored elements are now referencing the elements in referenced project.

Refactor diagram

To refactor diagram means to refactor the diagram as well as the elements on the diagram. As the steps are pretty close to refactoring model element, as described above, please read refactor model elements before reading this section.

  1. Right click on the diagram that you want to refactor and select Utilities > Refactor to Referenced Project... from the popup menu.
    Refactor a class diagram
    Refactor a class diagram
  2. You are prompted for saving project. Click Yes. If you click No, refactor will stop.
  3. If the Include Related Diagrams window appears, this means that one or more of the elements in the selected diagram has been visualized in another diagram (as listed on the left of window) with master view created. Read step 4 in the previous section to learn how to resolve the relationships.
  4. Refactor not only moves the selected elements to referenced project, but also those related elements. Read step 5 in the previous section to learn how to carry on.
  5. Once the refactoring is complete, the project will reopen itself. From now on, you can access and use the refactored elements through the Model Explorer. Select the referenced project under the drop down menu. Drag to diagram the element(s) to use. Note that auxiliary views of refactored elements are now referencing the elements in referenced project.
 
5. Duplicating element from linked project Table of Contents Chapter 4. Model element nicknaming
 

Technical Support

Have technical issues or suggestions? Please contact Visual Paradigm Support Team.

Sales Support

Have questions related to registration, licensing or payment? Feel free to contact Visual Paradigm Sales Team.

Discussion Forum

Share your suggestions of opinions at VP Discussion Forum.