Skip to content
James Hodgson edited this page Apr 3, 2014 · 51 revisions

#Step-by-step Re-factoring Problems & Solutions

  • Please ensure to run God Class, Long Method, Type Checking and Feature Envy while using JDeodorant.
  1. [AModel] (#wiki-aModel)
  2. [AView] (#wiki-aView)
  3. [BitmapJsonConverter] (#wiki-bitmapJson)
  4. [BrowseActivity] (#wiki-browse)
  5. [BrowseView] (#wiki-browseView)
  6. [Cache] (#wiki-cache)
  7. [CommentController] (#wiki-commentControl)
  8. [CommentListModel] (#wiki-commentListModel)
  9. [CommentManager] (#wiki-commentManager)
  10. [CommentModel] (#wiki-commentModel)
  11. [CommentPush] (#wiki-commentPush)
  12. [CommentSearch] (#wiki-commentSearch)
  13. [CreateCommentActivity] (#wiki-createComment)
  14. [EditCommentActivity] (#wiki-editComment)
  15. [EditMyProfileActivity] (#wiki-editMyProfile)
  16. [ElasticSearchResponse] (#wiki-elasticSearchResponse)
  17. [ElasticSearchSearchResponse] (#wiki-elasticSearchSearch)
  18. [GeoTopicsApplciation] (#wiki-geoTopicsApplication)
  19. [Hits] (#wiki-hits)
  20. InspectCommentActivity
  21. InspectOtherProfilesActivity
  22. InspectProfileActivity
  23. [MapsActivity] (#wiki-maps)
  24. [MyBookmarksActivity] (#wiki-myBookmarks)
  25. [MyCommentsActivity] (#wiki-myComments)
  26. [MyFavouritesActivity] (#wiki-myFavourites)
  27. [ProfilePush] (#wiki-profilePush)
  28. [ProfileSearch] (#wiki-profileSearch)
  29. [CacheIO] (#wiki-CacheIO)
  30. [ReplyLevelActivity] (#wiki-replyLevel)
  31. [StartActivity] (#wiki-start)
  32. [TopLevelActivity] (#wiki-topLevel)
  33. [User] (#wiki-user)
  34. [UserController] (#wiki-userController)

# AModel

  • No Bad Smells

# AView

  • No Bad Smells

# BitmapJsonConverter

  • No Bad Smells

# BrowseActivity

  • No Bad Smells

# BrowseView

  • No Bad Smells

# Cache

  • God Class - File + Load - FIXED

Before: JDeodorant recognized that the cache class had too many responsibilities and such it was too large.

Recommended Action: Recommended that we encapsulate the cache IO into it's own class.

Action: Moved the cache IO code using JDeodorant then renamed the class CacheIO to be more in line with its actual duties.

Result: The cache class now handles the internal working of the cache however it does not handle read and write to disk. This is delegated to the CacheIO class now.

  • God Class - cache - FIXED

Before: JDeodorant recognized that the cache class had more method's it wanted to extract due to too many responsabilities

Recommended Action: The JDeodorant recommended extractions left the cache class with zero responsibilities so we recommend manually doing a few of the suggested changes but not the rest. Ignoring the rest of the JDeodorantgod class recommendations.

Action: Moved the path variable into the CacheIO class and initialize it through the constructor. Also moved the load method into the CacheIO since it involves direct cache IO.

Result: The cache class now has a smaller amount of responsibilities making it a more concise class.

  • Feature Envy - Move Method - FIXED

The above re factoring removed the JDeodorant recommendations for feature envy.

# CommentController

  • God Class - new - NOT FIXED
  • Long Method - updateComment - NOT FIXED
  • Feature Envy - updateComment - NOT FIXED
  • Feature Envy - newReply - NOT FIXED
  • Feature Envy - newTopLevel - NOT FIXED

# CommentListModel

  • God Class - list - NOT FIXED

# CommentManager

  • God Class - new + M - NOT FIXED
  • God Class - comment + refresh - NOT FIXED
  • Feature Envy - refresh - NOT FIXED
  • Feature Envy - refreshMyComments - NOT FIXED
  • Feature Envy - refreshMyBookmarks - NOT FIXED
  • Feature Envy - refreshMyFavourites - NOT FIXED
  • Feature Envy - newTopLevel - NOT FIXED
  • Feature Envy - newReply - NOT FIXED
  • Feature Envy - updateComment - NOT FIXED
  • Feature Envy - getComment - NOT FIXED

# CommentModel

  • God Class - stamp + time + put + M + date - NOT FIXED
  • God Class- level + M + es + top - NOT FIXED

# CommentPush

  • No Bad Smells

# CommentSearch

  • God Class - model + pull + comment - NOT FIXED
  • God Class - repli - NOT FIXED

# CreateCommentActivity

  • No Bad Smells

# EditCommentActivity

  • No Bad Smells

# EditMyProfileActivity

  • No Bad Smells

# ElasticSearchResponse

  • No Bad Smells

# ElasticSearchSearchResponse

  • No Bad Smells

# GeoTopicsApplication

  • God Class - client + profil - NOT FIXED
  • God Class - client - NOT FIXED

# Hits

  • No Bad Smells

# InspectCommentActivity

  • No Bad Smells

# InspectOtherProfilesActivity

  • Feature Envy - updateUi - NOT FIXED

# InspectProfileActivity

  • No Bad Smells

# MapsActivity

  • No Bad Smells

# MyBookmarksActivity

  • No Bad Smells

# MyCommentsActivity

  • No Bad Smells

# MyFavouritesActivity

  • No Bad Smells

# ProfilePush

  • No Bad Smells

# ProfileSearch

  • No Bad Smells

# CacheIO

  • No Bad Smells

# ReplyLevelActivity

  • No Bad Smells

# StartActivity

  • No Bad Smells

# TopLevelActivity

  • No Bad Smells

# User

  • God Class - location - FIXED

Before: JDeodorant recognized that the user class had too many responsibilities and was much too large.

Recommended Action: The JDeodorant recommended extractions were to move the location related code into another class.

Action: Moved the location related code into another class to encapsulate it as UserLocationServices. Also moved any supporting code that was only used by these functions. Had to manually clean up the re factored class as it contained unnecessary code that was never used as well as some poorly named elements.

Result: The user class now delegates its location based functionality to a helper class.

  • God Class - file - FIXED

Before: JDeodorant recognized that the cache class handled IO when it could delegate it to another helper class.

Recommended Action: The JDeodorant recommended the extraction of some of the IO in the user class.

Action: Moved the recommented IO plus moved the rest that it did not suggest to move. Re worked the main load/store code for the user in order to allow it to move to another file.

Result: The user class no longer directly handles and of it's disk IO operations it delegates them to the UserIO class. The main user class is now much shorter and has less responsibilities.

  • God Class - ID, Favourites, Bookmarks, comments & Profile - IGNORED

Before: JDeodorant determined that the code for handling the users profile ID, list of favourites, list of bookmarks and other profile code should be moved to individual class'

Recommended Action: Recommend not implementing any of these changes. This would involve creating many class files which would make the user class much harder to manage. On top of this the responsibilities of the user class would reduce to meer delegation and we feel that the user class is completly capable of keeping track of its own list of favourites, bookmarks and comments as well as the few fields in its profile.

Action: Did not take any.

Result: The user class remains in controls of its direct fields such as user name, profile picture and its list of favourites.

# UserController

  • Feature Envy - favourite - FIXED

Before: JDeodorant identified feature envy in the favourite method.

Recommended Action: The JDeodorant recommendation was to move this method to the user class.

Action: Moved the method that handled adding or removing favourites into the user class.

Result: The user controller no longer decides if it removes or adds a favourite it simply delegates to the user class which is the rightful place where this decision should be made.

  • Feature Envy - bookmark - FIXED

Before: JDeodorant identified feature envy in the bookmark method. This method is handling responsibilities that are not for the controller to handle.

Recommended Action: The JDeodorant recommendation was to move this method to the user class.

Action: Moved the method that handled adding or removing bookmarks into the user class.

Result: The user controller no longer decides if it removes or adds a bookmark it simply delegates to the user class which is the rightful place where this decision should be made.

Clone this wiki locally