AutoPlug-Client icon indicating copy to clipboard operation
AutoPlug-Client copied to clipboard

Refactored code to resolve implementation as well as design smells and increase maintainability.

Open Drashti2608 opened this issue 1 year ago • 1 comments

I introduced below given test cases utilizing Mockito to enhance the testing coverage of the project.

  1. testGenerateNewKey(): To test GenerateNewKey() method of UtilsRandom class.
  2. indexOf_singleOccurrence(): To test indexOf() method of UtilsString class.
  3. testExpectInput(): To test expectInput() method of UtilsLogger class.

Furthermore, I have also attempted to remove some of the implementation code smells by performing below given methods.

  1. Performed 'Extract method' on installMod() method to reduce the Cyclomatic complexity of the method..
  2. Performed 'Decompose conditional' to reduce the complexity of conditional statement in preVisitDirectory() method of FileManager class.
  3. Performed 'Extract method' on SyncFilesManager() method of SyncFileManager class to reduce the Cyclomatic complexity of the method.
  4. Renamed variables 'mods_update_check_name_for_mod_loader' and 'plugins_updater_web_database_min_usages' to remove the code smell of 'Long Identifier'. I have used 'Designite' tool to detect the smells present in the code.

In further refactoring I have performed below given methods to resolve the design smells present in the code:

  1. Extract class:
  • FileManager.java class is handling multiple responsibilities. I've refactored the code by extracting related methods into a new class, FileSearcher.java. This enhances modularity and maintainability by focusing each class on specific responsibilities.
  • ConFileManager.java class has multiple responsibilities, which makes it less cohesive. Refactored the code by creating a new class, FileSystemUtils.java, and extracting the related method to that class.
  1. Replace conditional using polymorphism:
  • In the MainWindow class, Made changes to improve how we detect the type of theme. Instead of using many if-statements, I introduced ThemeSetup interface. All the theme types implement this interface. This change makes the code easier to manage and ready for adding new types of themes in the future. Hence, MainWindow class also adheres to Open Closed principle.
  1. Move method:
  • From TaskServerUpdater class, moved a couple of methods to UpdaterConfig class to remove the design smell of Feature envy. These methods belonged more to UpdaterConfig class than TaskServerUpdater class.

Drashti2608 avatar Mar 29 '24 18:03 Drashti2608

I have made the suggested changes to the code and have committed them. Could you please review them? I have also performed Move method, Extract class method and Replace conditional with polymorphism method to enhance the code readability and maintainability. Please have a look at them as well.

Drashti2608 avatar Mar 31 '24 18:03 Drashti2608

@Drashti2608 any news?

Osiris-Team avatar Jun 23 '24 18:06 Osiris-Team