Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refactoring #1915

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

Dhruvik6
Copy link

I applied refactoring on 2 methods getRandomPoint, overlaps.

  1. Extract Method: I applied extract method on getRandomPoint by extracting complex logic from the method and placing it into two smaller task specific methods. Below are the extracted methods:
    i. randomizePointOnEllipse() This method is responsible for calculating a random point on an ellipse.
    ii. randomizePointWithStroke() This method provides randomness based on the stroke width.

  2. Decompose Conditional: I decomposed conditions in overlaps method and created three new methods to reduce conditional complexities in the method. Below are the newly created conditional methods:
    i. checkOverlapWithRotation() This method checks for overlap between the current object (this) and another AbstractCanvasObject (that) considering the rotation.
    ii. checkOverlapWithoutRotation() This method checks for overlap between the current object (this) and another CanvasObject (other) without considering rotation.
    iii. checkContains() checks if the provided CanvasObject (obj) contains the specified Location (loc) using the contains method with a false flag.

  3. Introduce explaining variable: I created a static explaining string variable named results which contains “result” as a value. This string literal was repeatedly used throughout the class without declaration and this can create refactoring process complex.

Also,
Refactored this three classes:

  1. Extract Class: SvgReader class had multiple methods with unrelated responsibility. There were nine methods related to creating shapes and other six were related to getting properties of the components. I created new class PropertyReader for property related methods and kept shape related methods in SvgReader.

  2. Replace conditional with polymorphism: In class SelectTool, the setMouse method contains a switch statement that performs different actions based on the value of curAction. This is a clear case of conditional logic that can be replaced with polymorphism. Refactoring this will make it more flexible to add new actions without modifying the setMouse method.

  3. Move Method: The open and save methods in the HdlFile class were used only in the HdlContentEditor class. The open method reads a file and sets the text of the HdlContentEditor, while the save method writes the text of the HdlContentEditor to a file. It is more practical to move this methods to HdlContentEditor class because they are more related to the responsibility of this class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant