Two Flash Light 是我在多年前寫的小型Android project,當初寫的時間很趕加上也沒什麼設計模式,原則和重構等等的概念。
因此無論是從具體的程式碼實作或是高層的抽象設計都是一塌糊塗。(不過它仍然活在google play上好好的)。
由於種種的缺陷因此把它拿來當作重構的目標,似乎再適合也不過。
接下來重構的過程都會一步一步紀錄在這裡,也會將它開源到github上。(https://github.com/testfoxx/TwoFlashLight.git)
確定重構前已經建立好一切的準備。包含version control tool(git) , CI Server(Jenkins)等等。
git clone 之後會是一個TwoFlashLight的資料夾,source code 的部份放在 Two_FlashLight 資料夾中。
相關的測試類別放在 TwoFlashLight/Two_FlashLight/test。
要說明的是重構前必須建立測試環境,以避免重構失敗所造成的影響。
使用工具為 android 的 InstrumentationTestRunner 搭配 jenkins emma plugin
emma plugin 可以讓你了解目前的測試覆蓋率有多少。每一次 merge code 都會更新覆蓋率。
 
OK~ 那麼就開始嘗試重構吧。
refactoring part1
refactoring part2
refactoring part3
refactoring part4