partial class SpacewarGame : Microsoft.Xna.Framework.Game
{
Interestingly, I had apparently found part of a class. Being the diligent person that I am, I immediately set out to find the rest of it. Unfortunately, my search was in vain because this was the only declaration of the SpacewarGame class. I immediately wondered what benefit was bestowed by the partial keyword. A quick wikipedia search reveals the following:
A partial class, or partial type, is a feature of some object oriented computer programming languages in which the declaration of a class may be split across multiple source-code files, or multiple places within a single file.
My first thought is why is this actually needed? Apparently partial classes come in handy when dealing with generated code. The classic example is when dealing with windows form code. The generated code is hidden from the developer and she can easily add to the class without worry of losing those changes if and when the class is re-generated. Hmm... that sounds fair.
However, it apparently does not stop there! Another valuable benefit includes multiple developers working on the same class without stepping all over each other since they will be working on different files. This would seem to work especially well where locking strategies are implemented with version control software. Or, how about facilitating the modification of big classes? Ok, now I am starting to feel uncomfortable. In my view, both of those situations are a smell of bigger issues.
But I am told that I should not be concerned. The compiler collects all the class pieces and stitches them together, ensuring that a valid type can be constructed. In terms of maintenance, if I were ever unfortunate enough to work on a project that over utilized partial classes, I could rely on the Visual Studio Class view for easily accessible, complete class definitions.
Well, I am not convinced. Even though partial classes may have a use, in my view it is somewhat limited. I do see, however, that the ability to abuse them is quite large. I feel that I encountered the beginnings of that in the Spacewar code-base. In the end, I see this as another example of a well-intended feature making developers lives harder rather than easier.
On a side note, Ruby's mixins have been compared to partial classes, however I think they are fairly different animals.
If you want to learn more about partial classes check out the following links: msdn magazine , msdn reference