How to refactor tightly coupled classes?

后端 未结 6 1061
天命终不由人
天命终不由人 2021-02-10 02:35

I\'m trying to refactor a big tightly coupled application and trying to make it more maintainable and flexible.

I\'ve got many unit tests, so I\'m hoping to refactor ste

6条回答
  •  借酒劲吻你
    2021-02-10 02:54

    In all seriousness, refactoring is not an undertaking to be taken lightly, especially in tightly coupled systems. It can often seem like a worthwhile task before it has been performed, but from my experience, it can soon become a burden once started as it is often more likely to introduce new bugs than solve any existing issues.

    Before embarking on a major refactoring, you should consider what the gains will be and what alternatives there are (such as creating a new product from scratch, refactoring only the parts that need it right away, etc.). You should certainly have a good understanding of the architecture, roles, and responsibilities before starting, as well as the expected and existing behavior to ensure that you know when you've broken something.

    Also, it can be beneficial to draw up a design of how it will be after the refactoring and how that maps to the current implementation so that you can stay on point. You should also regression test as often as possible.

    It can be frustrating to the perfectionist when a design is quite obviously in need of refactoring, but sometimes one has to consider the cost/benefit of the changes and concede the battle. If you must make the changes, tread carefully and don't try to do too much at once.

提交回复
热议问题