whattofix.com— Is Microsoft going too far with partial classes? This commentary looks at the reasons for using them and finds them lacking.
May 18, 2006View in Crawl 4
I guess you actually have to code a large project first before you find an instance where partial classes are useful. The perfect example is VS 2005 where designer code is put in its own partial class file. Before in VS 2003 an interface file would be so messy with thousands of lines of interface code and variables, and then below it your own custom code. Now the custom code is all in a nice, small, manageable, file which is much cleaner to work with than before.In my own projects I sometimes end up with a large class file where a set of functions have to deal with interop, another set for packet handling, and a set of functions for logic. It might come out to 3000 lines of code which is a bitch to traverse through. With partial classes I can put those three function sets into their own files so now when I want to look up logic code its all together in its own manageable file. And its easier for others to understand and work with also.
swax. dude.If you're writing 3000 line classes, you need to re-factor a bit. I've written and maintained monster projects. Partial classes don't help. Look at it this way: if you can logically separate the pieces of your class into smaller units, why are you keeping them all together? Sounds like those interop functions are a data tier, right?
swaxMay 18, 2006
I guess you actually have to code a large project first before you find an instance where partial classes are useful. The perfect example is VS 2005 where designer code is put in its own partial class file. Before in VS 2003 an interface file would be so messy with thousands of lines of interface code and variables, and then below it your own custom code. Now the custom code is all in a nice, small, manageable, file which is much cleaner to work with than before.In my own projects I sometimes end up with a large class file where a set of functions have to deal with interop, another set for packet handling, and a set of functions for logic. It might come out to 3000 lines of code which is a bitch to traverse through. With partial classes I can put those three function sets into their own files so now when I want to look up logic code its all together in its own manageable file. And its easier for others to understand and work with also.
batdudeMay 18, 2006Submitter
swax. dude.If you're writing 3000 line classes, you need to re-factor a bit. I've written and maintained monster projects. Partial classes don't help. Look at it this way: if you can logically separate the pieces of your class into smaller units, why are you keeping them all together? Sounds like those interop functions are a data tier, right?