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 To remove code smells #1

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

Conversation

Hrishita
Copy link

@Hrishita Hrishita commented Mar 25, 2022

Purpose of PR

This PR includes some code refactoring to remove code smells from the project.

Changes Made

Following refactoring has been performed:

  • Extract Method

    • Extracted a method calculatePowerLevel from update method from BaseInfo class to remove complex-method implementation smell.
    • The cyclomatic complexity of this method was 103.
    • This refactoring increased method readability.
  • Rename Variable and Method

    • Renamed all the classes to make them uniform across the project.
    • Renamed a method createStraightRoadSection in terrain.java as there was typo in method name.
    • Renamed put method to createArbitraryVertex method to give it a meaningful name.
    • Renamed method from change to changeVertex3DGeometry to make it more meaningful and improve understandability.
    • Renamed object o of SolidObject class to solidObject to improve code understandability.
  • Move Method Refactoring:

    • Moved addStealthTank method from scoutingMangerAI to SolidObject.
    • Moving this method resolved feature envy smell as this method was more interested in SolidObject class.
  • Pull Method:

    • The subclass HeavyTank, and LightTank had duplicate variables which are pulled to an intermediate class Tank
    • The above classes also had duplicate code in method fireBullet() thus performed extract method and pull method.
    • Extracted method spawnExplosion and pulled it to intermediate parent class Tank
  • Push Method:

    • clonePolygons method is pushed down from the parent class SolidObject.
    • This method is only being used by Harvester, ConstructionYard, ConstructionVehicle,and Drone class.
    • All the remaining classes were rejecting the cloneObjects method which introduced Rebellious Hierarchy Design smell.
    • To remove this smell intermediate layer is introduced and above class are extended from this layer.

If you have any suggestions or want me to accommodate more changes, I'll be more than happy to contribute.
Feel free to reach me out at hrishitamavani@gmail.com.

Cheers

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