使用反射来改变实现

发布于 2024-09-17 01:23:00 字数 299 浏览 6 评论 0原文

我的老板将自己视为 OOP 大师,而我则将他视为业余程序员。他负责我们的 Sage 开发,为我们客户的 Sage 安装添加自定义要求。他最近对反思感到非常兴奋,他正在代码中反思 Sage 的程序集并更改私有成员和事件处理程序。我认为这不是一个好主意,但他驳斥了我,说圣人认为他能做到这一点真是太棒了。我认为这是不好的做法,因为它效率低下,而且如果他们在任何时候改变其实现,我们的代码都可能崩溃。我的意思是,通常开发人员出于某种原因将某些东西设为私有,对吧?

这方面的一般规则是什么?

如果这看起来是一个愚蠢的问题,非常感谢和道歉。

保罗

My boss regards himself as a OOP Guru where as I consider him as a hobbyist programmer. He handles our Sage development, adding custom requirements to our clients Sage installations. He recently has got very excited by reflection, he is reflecting on Sage's assemblies in code and changing private members and event handlers. I thought this was not a good idea but he shot me down stating that Sage thought he was amazing that he could do it. I believed that this was bad practice because it was inefficient and because if they change their implementation at any point our code could collapse. I mean usually a developer has made something private for a reason right?

What's the general rule regarding this?

Many Thanks and apologies if this seems like a stupid question.

Paul

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悲欢浪云 2024-09-24 01:23:00

你是对的。如果您依赖于第 3 方库的实现细节,那么您最好准备好在第 3 方库更新时重写所有内容,并准备好在您使用某些“无害”值更改某些私有变量时出现意外的副作用。

答案是,只有当你百分百确定自己正在做的事情并且准备好面对后果时才去做。

You are right. If you depend on implementation details of 3rd party library, you better be ready to rewrite everything when 3rd party library is updated and for the unexpected side effects when you change some private variable with some "innocent" value.

The answer is do it only if you 100% sure in what you are doing and you a ready to face the consequences.

纸伞微斜 2024-09-24 01:23:00

您不应该修改现有的程序集 - 结果可能是未知的并且肯定不受程序集供应商的支持。此外,此类更改将丢失保证程序集是供应商提供的版本的程序集签名。

基本上,任何事情都可能发生,所以除非您愿意进行非常严格的测试,并且没有供应商支持可以依靠,否则请远离!

You shouldn't modify existing assemblies - the results are likely to be unknown and definately not supported by the assembly vendor. Also, such changes will lose the assembly signing that guarentees the assembly is the version shipped by the vendor.

Basically, anything could happen, so unless you're willing to do very rigorous testing, with no vendor support to fall back on, stay well away!

花伊自在美 2024-09-24 01:23:00

程序集的每个新版本都可以有完全不同的实现。 Sage 的软件更新可能会使您的 Boss 代码完全失效,并且需要完全重新开发才能重新建立相同的功能。

举个真实的例子: StringBuilder< /a> 在 .NET 3.5 内部使用 string,在 .NET 4 中它使用 char[] 请参阅此 最近的问题。)

Each new version of an assembly can have a completely different implementation. A software update from Sage could completely invalidate your Boss's code, and would require completely redevelopment to re-establish the same functionality.

For a real example: StringBuilder in .NET 3.5 used a string internally, in .NET 4 it uses a char[] see this recent question.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文