Over the years I have heard that some folk actually use partial classes to help assist in-team collaboration efforts, yet I have yet to meet such people. If you have a standard source control system that allows you to merge then surely this is just as good?
The reason I bring this up is that I was recently extending some code that is designer driven, well that’s not really true there is no designer but what the program generates is some generic code that is partial so you can cleanly extend it without wading through all the nonsensical automated comments and clear lack of sane code formatting.
If you were to look on MSDN there are two major points which are mentioned about the partial keyword (shamelessly lifted from the MSDN site):
- When working on large projects, spreading a class over separate files allows multiple programmers to work on it simultaneously.
- When working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when creating Windows Forms, Web Service wrapper code, and so on. You can create code that uses these classes without having to edit the file created by Visual Studio.
Now I can totally see that partial classes for designer driven code is very good, e.g. WinForms which if you use the designer to build just throws in a tonne of glue for you that you really don’t want to damage your eyes by looking at – but do we really use partial classes in these large projects?
I’d be interested to know if folk have actually used partial classes in the way in which the first point alludes to from MSDN.
p.s. (final reminder) please post any comments on my new blog – http://msmvps.com/blogs/gbarnett