DEV Community

Cover image for Developer diary #24. Refactoring
Kiolk
Kiolk

Posted on

Developer diary #24. Refactoring

I’ve spent several hours refactoring my Flutter code. Why did I do this? The key reason was the complicated existing logic. My code seemed like a spaghetti, with dependencies leaks through specific layers. The main reason why it happened was the use of new libraries, and I was focused on implementation rather than the quality of the code. In the face of new functionality, I felt real fear because I understood it would be complicated.

I decided to refactor my code by focusing on layers of responsibility. First of all, I extracted several interfaces with clear boundaries of their responsibility. I did this in parallel with existing code to avoid large refactoring when nothing working. I did this step by step. At the same time, I kept the part clear that should be variable and will play a role as a different strategies. For the creation several objects, I selected the builder pattern for clarifying creation.

As a result, I got a clear code with lower coupling and clear division by layers of responsibility. I wondered how easy It was to add new functionality. I just added a new strategy and implemented the required functions. It will be so easy to add new feature in the future. Refactoring is an important part of the development, especially, when you focus on adding new functionality. My code isn’t optimal; I think, I should do an additional round of refactoring to make it better. It should be an iterative process.

You can find me in X, GitHub, medium or LinkedIn. Thanks for your time and see you in next post.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More