C#: Why you should avoid using partial classes

I have noticed this in my work with existing code; for some reason there are programmers out there who like using partial classes. As someone who has experienced this, let me quote myself on this:

If I have to go looking for your crap in different files, named unrelated to each other and calling stuff that is located in a different file, you are doing something wrong

As harsh as that might be, it is true; they are very confusing.

There is a good reason for why partial classes are part of Microsoft’s languages; so that they can wire your user interface items in a designer class which you can directly access, without inheritance, from your working class.. This is genius approach, but that does not mean you should make heavy use of this. Eventually you will confuse yourself. This concept is not to be confused with inheritance either, because they are completely different things. If you want to obtain the effect of broken up files, then use a system of inheritance instead. Though you will using a powerful programming element in the most useless way possible, at least it gives your fellow programmers some context to why you stuff is broken into 4 code files, representing the same class.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s