在Delphi中绕过循环引用 [英] getting around circular references in Delphi

查看:180
本文介绍了在Delphi中绕过循环引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



可能是较新版本的delphi或一些魔法黑客或什么东西?



我的delphi项目有10万行代码,主要基于单例类。我需要重构这个,但这意味着几个月的循环引用地狱:)

解决方案

我一直在维护在过去十年中接近一百万行的遗留代码,所以我明白你的痛苦!



在我维护的代码中,遇到循环使用时,我经常发现它们是由单元A中的常量或类型定义引起的,单元B.(有时它也是A单元中的一小部分代码(甚至全局变量),也是单元B所需要的。



在这种情况下我很幸运!)我可以把代码的部分小心地提取到包含常量,类型定义和共享代码的新单元C中,然后单元A和B使用单元C.



由于我不是软件设计方面的专家,因此我发布了上述内容,意识到这里有很多人比我更了解,希望我的经验将会有所帮助给你。


Is there a way of getting around circular unit references in Delphi?

Maybe a newer version of delphi or some magic hack or something?

My delphi project has 100 000+ lines of code mostly based on singleton classes. I need to refactor this, but that would mean several months of "circular reference" hell :)

解决方案

I've been maintaining close to a million lines of legacy code for the past 10 years so I understand your pain!

In the code that I maintain, when I've encountered circular uses, I frequently have found that they are caused by constants or type definitions in unit A that are needed by unit B. (Sometimes it's also a small bit of code (or even, global variables) in Unit A that is also needed by unit B.

In this situation (when I'm lucky!) I can carefully extract those parts of the code into a new unit C that contains the constants, type definitions, and shared code. Then units A and B use unit C.

I post the above with some hesitance because I'm not an expert on software design and realize there are many others here who are far more knowledgeable than I am. Hopefully, though, my experience will be of some use to you.

这篇关于在Delphi中绕过循环引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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