tags:

views:

131

answers:

2

Which way is best practice and the best programming approach, Partial Classes or Individual classes?

+14  A: 

Only use partial classes where there's a clear benefit in separating out the logic for one class into multiple files. The most obvious example is where some part of the code is autogenerated - code generators should usually build partial types, to allow for them to be augmented by the developer.

They can also be useful when refactoring one class into two, to get a feel of what the classes will look like afterwards.

Those are the major use cases really - I wouldn't start using them too liberally; it makes it harder to work out where everything is. Obviously there are exceptions... for example the System.Linq.Enumerable class in .NET 3.5 must be huge, and it would make sense to implement that with partial types to end up with manageable files.

Jon Skeet
+1  A: 

Partial classes are great for the differentiation between the GUI interface that is auto-generated, and the partial class that corresponds to that for YOUR code makes sure you and code which is auto-generated don't step on each other's toes. Take advantage of that.

As for building your own custom classes / GUI controls, I would stay the same way. Let the IDE help with the visual cosmetics, and the rest of the partial class to perform your custom functionality.

DRapp