Partial classes – they have only one real use, right?

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 –

Data Structures and Algorithms book

Myself and Luca are currently working on a free e-book that should be out near the end of the year, it will be a companion to the Data Structures and Algorithms project located on CodePlex.

The book use’s pseudo code to describe the solutions that we have created so that it can be easily ported to many imperative OO languages like C#, C++, and Java (amongst others).

We are targeting this book at intermediate to advanced programmers, however we do cover some of the basics to give the reader a hand in getting up to speed pretty quick with the terminology used etc.

Presently we have a few good reviewers on board, however if you are interested in this area and would like to be a reviewer then please get in touch with me so I can add you to the reviewers list.

p.s. as you may have noticed my blog has moved to so please post any comments there.