如何重构紧耦合类? [英] How to refactor tightly coupled classes?

查看:139
本文介绍了如何重构紧耦合类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有很多单元测试,所以我' m希望一步一步地重构。



哪个设计&重组模式我应该考虑实施/申请来完成这个任务吗?



我可以想到一些:




  • 提取界面

  • <一个href =http://sourcemaking.com/refactoring/extract-method =nofollow noreferrer>提取方法

  • 依赖注入



还可以免费分享您自己的这种重构工作的经验和最佳实践。



更新



由于这个问题解释的原因,我正在进行重构。基本上,我无法实现一个插件系统,而不会提取几个接口,而这些接口是高度耦合的,这需要在40多个DLL中分离应用程序,以便编译没有循环引用的问题。

感谢所有的答案,在挣扎着很多不同的方式后,发现最好的做法是创建所有的接口。这让我可以自由地改变设计,我只打破了一天的建设(一天,因为项目很大,我需要修复这么多参考和单元测试+一些重构)。



日间提取和修复所有界面后,我可以自由创建单独的解决方案并进行设计。



第一步我认为应该将所有内容移动到界面,然后尝试去除内部的依赖关系。


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 step by step.

Which Design & Refactoring Patterns should I consider implementing / applying to accomplish this task ?

I can think of some :

Also feel free to share your own experience and best practices for this kind of refactoring job.

UPDATE

I'm carrying out this refactoring because of the reasons explained in this question. Basically I can't implement a plugin system without extracting an couple of interfaces and those interfaces are highly coupled which requires separated the application in 40+ DLLs to just compile without circular referencing problem.

解决方案

Thanks for all answers, After struggling with so many different ways I found that the best thing to do was creating interfaces for everything. This allowed me to change the design freely and I only break the build for a day (a day because the project was big and I need to fix so many references and unit tests + some refactoring).

After day extracting and fixing all interfaces I can create separate solutions and play with the design freely.

Basically first move I think should be moving everything to interfaces and then try to get rid of internal dependencies.

这篇关于如何重构紧耦合类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆