Partial classes permit splitting a single class, interface, or struct into multiple, separate files. There are several advantages to splitting these elements into many files, including permitting more than one developer to work on the same class. Paul Kimmel shows where partial classes are used and how you might use partial keywords to fine-tune your productivity.
Kind of on-topic:
Anyone have an opinion of of VS 2003 vs VS 2005?
My experience in the past is that initial major releases of MS dev tools have always been shaky. What’s 2005 like?
Lastly, anyone know of a good online review of 2005 (or one that compares 2003 & 2005)?
Thanks!
You can download the Express Editions (free products) or get a trial version of Pro or Team System here:
http://msdn.microsoft.com/vstudio/
You can also try out Visual Studio online at the MSDN Virtual Labs:
http://msdn.microsoft.com/virtuallabs/default.aspx
The article seems to focus on partial classes allowing multiple programmers to make changes to the same class. This is suggested as a workaround to the failings of sourcesafe.
As far as I can tell the only legitimate use for partial classes is to separate my code from that generated by the designer (no more “Designer generated code” regions, yay!) which I think is a good thing.
I can just imagine the mess in the source tree from using partials to separate programmer’s work:
class.cs – Original class.
class_2.cs – Someone else needed to add a method.
class_bs.cs – Oh, Brad worked on it too…
class_3.cs – You get the idea.
Perhaps use a decent source control system instead?
:]
I have to totally agree with you. A programmer with limited knowledge and an active imagination is the nightmare of any code maintainer.
You can really see the benifit of partial classes when you start using ASP.NET and XAML in Avalon. This allows you to potentially give a designer the interface to create and then pass the work to the developer. I beleive this is Microsofts plans and I thought I saw a product that alluded to this.
Well either way it is a bad idea in this article to allude this will help with source control. The person who wrote this article is probably the type of coder that I alluded to above.
You can really see the benifit of partial classes when you start using ASP.NET and XAML in Avalon. This allows you to potentially give a designer the interface to create and then pass the work to the developer. I beleive this is Microsofts plans and I thought I saw a product that alluded to this.
The product is Expression Interactive Designer (codenamed Sparkle):
http://channel9.msdn.com/ShowPost.aspx?PostID=116394
http://www.microsoft.com/products/expression/en/interactive_designe…
If you’re tempted to use partial classes, then your “god class” really ought to be split up into multiple, smaller classes. This is known as “refactoring”. Once you’ve done this, you won’t need to split up a class definition file into multiple files. Your code will be easier to understand and maintain, and there will be less of a likelihood that multiple developers will want to work on the same class at the same time.
I’m worried that developers will flock to partial classes because it encourages poor structural design.
I totally agree… partial classes are barely a good idea for generated code (mostly getting around poor navigation features in VS.Net IMO), and an extremely bad idea for anything else.
Generated code seperated from actual code is always a good thing. Definitely when you start throwing mark up langauges on top of the compiled code. In the case of ASP.NET and XAML it is a great thing. So that developers can work on code and designers can work on interfaces. I am not saying the process is perfect, but it is getting closer to the intent than ever before.
I never understood why Microsoft never separated the automatically generated GUI code from the manually generated code in VS. It’s not as if they didn’t have an example to compare with, that is Borland’s Delphi. It is even stranger that they didn’t do this from the beginning given that Anders Hejlsberg was one of the orginal designers of Delphi. There is some separation now in VS2005, but in VS2003 it’s all mixed up.
why would a interface coder and core coder want to work in the same file? Though decoupling core logics and interfaces into seperate modules/files is the way to go.
then fix that issue by doing resource files or stuff like that – dont let world+dog implement a class over 15 files, it WILL BE ABUSED!
From the article:
A pessimist might wonder […]Visual SourceSafe doesn’t support multiple simultaneous checkouts of the same file and isn’t known to merge file differences with eloquence and grace[…]SourceSafe’s tolerable deficiencies are somewhat mitigated.
😀 How very nicely put
In my world, we use better version/source control systems instead of inventing newer keywords
There are several advantages to splitting these elements into many files, including permitting more than one developer to work on the same class…..A pessimist might wonder……Whether intended or not, a nice benefit of partial classes is that SourceSafe’s tolerable deficiencies are somewhat mitigated.
Well, I am a pessimist when it comes to SourceSafe and if you think you should be using it maybe you should be considering another career. SourceSafe is not acceptable as a source control system under any circumstances, nor are half-baked ways of getting multiple developers on the same piece of code.
No, twice no, thrice no. Get a proper source control system and communicate with each other when developing. Chopping classes up into further parts just adds to the communication, complexity and development overhead.
Additionally, that’s what refactoring is about. If your class is too large maybe you should be looking at your classes a bit harder and splitting them up, or looking at your analysis and design?
You’ll find the partial keyword used in Windows Forms classes to split the part that’s managed by the designer and the part where you add your code into two separate files.
All this is is a way for Microsoft to sell you Team System, which is conveniently split up into architect and developer components, where each cost money and have separate licenses of course.
Edited 2006-01-16 15:26
This is what you get when you don’t have a Community Forum. Dumb ideas.
Microsoft developers are the scariest in the world.
– Like Static classes in Enterprise code.
Learn to code OOP first, before reinventing.