|
"Partial classes" is on of the new features of v2 that, while I totally get why Microsoft wanted to add it, I didn't really see any use of them beyond the vstudio code gen world. "Nested classes" was one of the features of v1 that, while I completely understood the theoretical point of them, I had a HECK of a time coming up with any possible senario where it would actually be useful and the Right Decision. And now, within the last week, I've ran across 2 instances where the combination of both of these features made the project better and more managable. I'll only talk about one of them because only one is my code :) I'm working on a control on v2 to get a feel for various new technologies we get to play with, like callbacks and new designer possibilities. One such new designer feature is the Smart Tags that pop open next to controls which give you quick access to various actions on the control. I'm using the smart tag to let you show or hide areas of the control, so you can see them as you set the various styles. Implementing these smart tag actions isn't quite as simple as it could be for the simple cases, but I can see that it's quite powerful. So, getting back on topic, the implementation requires a custom Designer for the control, an ActionList class which handles the selection of the smart tag actions, and a TypeConverter class that supplies the list of actions shown in the smart tag. Neither the ActionList nor the TypeConverter class are useful outside of the Designer and the ActionList needs to access members of the Designer which really should be private. Therefore, they are both prime candidates for being nested classes. However, having three classes in one code file can get tedioius with the scrolling and such. And that is where partial classes come in. Before partial classes I would have just set them as internal to avoid the problem, but that is more exposure than they require. So with partial classes, I put each nested class in its own file, with the parents' "partial class" declaration becoming an extended namespace of sorts. So with the combination of these two features, I now have the classes having the least amount of exposure they require while still getting all the file management features I would normally have with seperate internal classes. So ya, call me a convert.
|