Exercise 48: Team Rename Method Refactoring Posted: Nov 07
In this exercise, you will go through a workflow to perform a refactoring. The overall process includes:
- Setting up an issue at GitHub
- Creating an issue branch
- Performing the Rename Method refactoring
- Creating a pull request
- Accepting the pull request
- Closing the issue
- Deleting the issue branch (but don't do)
The following workflow must be followed to receive credit. Use the same commit messages as shown.
Set Up the Issue
- Create An Issue In GitHub, create an issue in your repository for the refactoring. The title of the issue is:
Explain what you will do as well as possible for the body of the messages.
- Assign Yourself to the Issue Once the issue is created, assign yourself to it so that others know you are working on it.
Set Up a Branch for the Issue
- Create an Issue Branch Instead of working on the branch
main
, you are going to work on the branch issue_n_ where n is the issue number, e.g., if the issue number is 1 then the branch name is issue1
. First, make sure you are in the branch main
. Then, create the branch:
Branches can be created via GitHub. However, please create this issue via the command line.
- You have created a new branch locally, but it does not yet exist at GitHub. To do so, you need to push it to GitHub. When you do so, you will see an error message. Enter the command that it shows you.
- Verify at GitHub that your branch exists.
Report For your report of the following, keep a list of all the git commands you enter. Keep them in order. Do not put any name, title, etc. For commits, enter the git commit short hash (first 7 characters) on the line after the git commit.
- You are going to perform a refactoring. The code must compile, build, and produce exactly the same result at every commit.
- Create a new method declaration in the ToDoList.hpp file. This is not a definition, only the declaration. Compile the program and get it to build successfully. Once done, commit using the commit message:
Push your changes to GitHub.
- Create a new method definition in the ToDoList.cpp file. This method definition will not have any contents and will return a 0. In other words, the shortest/smallest implementation that will get the program to build. Once done, commit using the commit message:
Push your changes to GitHub.
- Copy the contents of the old method
length()
definition to the new method size()
. Successfully build the program. Once done, commit using the commit message:
Push your changes to GitHub.
- At this point, both
size()
and length()
do the same thing. Now, change length()
(the old method) to call size()
(the new method). The definition of length()
should only have the call to size()
. Note that you must pass along the parameters and handle any return
statements.
Push your changes to GitHub.
- One-by-one, replace any calls of the method
length()
with a call to method size()
. Again, this must be done one call at a time. After each change, compile, build, and run successfully. Commit each time using the git command:
Push your changes to GitHub
- After all calls to length() are replaced, delete the definition (not declaration) of
length()
in ToDoList.cpp. Compile, build, and run successfully. Commit using the command:
Push your changes to GitHub
- Now delete the declaration of length() from ToDoList.hpp. Compile, build, and run successfully. Commit using the command:
Push your changes to GitHub.
At this point, the refactoring is complete.
Create a Pull Request
Create a pull request at GitHub. You want to pull from the branch issue1
into the branch main
.
Accept the Pull Request
Accept the pull request at GitHub. Typically, this would be done by another team member, but in this case, you can accept your pull request.
Switch to the main
branch in your cloned repository and pull the changes. The rename should appear in the code on the main
branch.
Close the Issue
- At this point, you have completed the issue and can close it. Do so at GitHub.
Delete the Branch
- The branch
issue1
has done its job and is no longer needed. All your commits on this branch are now in the branch main
.
- We could delete this branch, but do not do so for purposes of this assignment.