Ted is all excited about the upcoming partial classes (the ability to have a
class implementation spread over several source files) in the CLR. He
As part of the C# 2.0 release, Microsoft/ISO are introducing an interesting
new feature as part of the language; it’s not as sexy as something like
generics, perhaps, but I think it stands to serve as a far more powerful and
important feature in the long run: partial classes.
More specifically, he is worried about accidental overriding:
I can accidentally introduce, through overriding, errors into the code
because I don’t follow invariants assumed by the code-generator.
I fail to see how partial classes help mitigate this problem since nothing
prevents both you and the code generator to create methods with the same name
and signature in different files.
There is benefit to partial classes, though, but Ted seems to miss it.
The problem with the way code generation is typically performed nowadays in Java
is with inheritance:
- You extend a generated class or
- A generated class extends yours.
The problem with solution 1) is that it makes it impossible for your class to
extend another class, since Java and C# only support single inheritance of
implementation. Partial classes can come in handy in such a case.
This feature is interesting but it also opens the door for the resurrection
of long-forgotten linker problems, since a compilation phase is no longer
guaranteed to produce a valid class… It will be interesting to see how
Microsoft handles this problem.