Stupid Question 68: What do we use partial classes for?
partial classes, what can we use them for?
I have to ask. I don’t remember how this came up,- oh wait I do. At the user group we discussed the several classes in one file, and started talking about partial classes. Today I started thinking a bit more about partial classes. I honestly can’t think of many scenarios when I have used them or would used them. I have when I have worked with autogenerated code, but aside from that I really can’t think up any other good usage for them. When doing some research and reading what Scott Mitchellsays about partial classes:
“Partial classes and partial methods are two programming language features of .NET programming languages that make it possible for developers to extend and enhance auto-generated code”
it does seem like I am spot on. But, are there any other good usage for them? Even though they are intended for this particular usage (extending auto-generated code) - can they be nice to have in any other particular scenarios? I tried coming up with ideas, but most of them seem to break the holy rule that classes should not to to many things (in other words no God-classes), and splitting up a class might indicate that it does just that. What do you think?
Last modified on 2012-10-26