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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay