Refactoring with SOLID principles in mind
One of the reasons I built Dotz was to see how it would survive change. The first release was simple exactly for this reason - I planned to return to add more features and see how simple or difficult it would be. I managed to add a new feature to Dotz recently - when you connect the dots so that the lines form a shape (like a rectangle or square), all dots of the same color will disappear, adding to your score. As I introduced this feature, I reflected on this refactoring exercise and SOLID principles.
Step 1: Make it work
My initial approach was to take the easy road by modifying the Move class directly. I realized that it was missing some core functionality, such as getUniqueDotCount or getGroupedDots methods. I've also fixed an issue in destroyDots which appeared only after it was forced to remove a lot of dots from the screen.
At the end, I've expanded it to check if a square was present and schedule more dots of the same color for removal.
I coded, tested and released it. And that's when it hit me. I did two things: I fixed issues within the Move class and I've modified its behavior. Now, fixing issues is fine. Modifying existing behavior in the same class has short legs - what if I want to add more functionality? What if I wanted to give a choice between game modes?
