JavaRTS
JavaRTS copied to clipboard
Code Refactoring To remove code smells
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
fromupdate
method from BaseInfo class to remove complex-method implementation smell. - The cyclomatic complexity of this method was 103.
- This refactoring increased method readability.
- Extracted a method
-
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 tocreateArbitraryVertex
method to give it a meaningful name. - Renamed method from
change
tochangeVertex3DGeometry
to make it more meaningful and improve understandability. - Renamed object
o
ofSolidObject
class tosolidObject
to improve code understandability.
-
Move Method Refactoring:
- Moved
addStealthTank
method fromscoutingMangerAI
toSolidObject
. - Moving this method resolved
feature envy smell
as this method was more interested in SolidObject class.
- Moved
-
Pull Method:
- The subclass
HeavyTank
, andLightTank
had duplicate variables which are pulled to anintermediate 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
- The subclass
-
Push Method:
-
clonePolygons
method is pushed down from the parent classSolidObject
. - This method is only being used by
Harvester
,ConstructionYard
,ConstructionVehicle
,andDrone
class. - All the remaining classes were rejecting the
cloneObjects
method which introducedRebellious 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 [email protected].
Cheers