我想知道为什么C#/VB中甚至存在"部分类"的概念.网我正在开发一个应用程序,我们正在阅读一本(实际上非常好)与我们正在工作中实现的开发平台相关的书.在这本书中,作者围绕平台API提供了一个大型代码库/包装器,并在教授平台开发的不同主题时解释了他是如何开发的.
总之,长话短说——他到处使用分部类,作为在C#(IMO)中伪造多重继承的一种方法.我不明白他为什么不把这些课分成几个班,然后用作文.他将有3个"部分类"文件组成他的基类,每个都有3-500行代码...在他的API中多次这样做.
Do you find this justifiable?如果是我,我会遵循S.R.P.并创建多个类来处理不同的所需行为,然后创建一个基类,其中包含这些类的实例作为成员(例如合成).为什么微软甚至在框架中加入了部分类?他们取消了在C#中扩展/折叠每个作用域级别的所有代码的功能(这在C++中是允许的),因为这显然只是允许坏习惯——在我看来,部分类是一样的.I guess my question is: Can you explain to me when there would be a legitimate reason ever to use a partial class?
EDIT: I'm aware that for Web/WinForms there is no other choice. But outside of this? Why didn't MS just put some different keyword for gluing code-genn'ed classes together? Or is there really a legit design scenario that merits it?个
I do not mean this to be a rant / war thread. I'm honestly looking to learn something here. When should partial classes be used in code design? Simple question, no need to close
谢谢