The secret success (it’s not a secret anymore) of Microsoft was GUI (Graphical User interfaces).
In case you are an old guy like me, you would remember until 80s the operating system were DOS based, with those black windows and cruel commands like
Suddenly when Microsoft launched Windows 3.X, the whole world went crazy. Simple User Interfaces, no need to remember those DOS commands and windows became THE NUMBER ONE OPERATING SYSTEM in every end user desktop.
So Microsoft tasted its first success by the magic word GUI (Graphical User Interface).
They wanted to take the same success story to PROGRAMMING and Visual Studio was born. A new era of RAD (Rapid Application Development) and visual programming started.
In order to enforce the GUI magic, Microsoft introduced Visual Studio where developers get User Interfaces like grids, buttons, combo boxes, etc. They can drag and drop these UI elements and create user interfaces quickly. Developers also had the luxury to write code easily when these User Interfaces where clicked.
“Behind every successful RAD, there is code behind”.
Now there are two kinds of code in RAD tools:
Now the biggest challenge for Microsoft was how to keep custom and auto-generated code separate. Because if they are kept in a single file, there are high chances that the code which is auto-generated can overwrite the custom code written by developer leading to havoc.
The answer was “Partial classes”. The concept of partial class is your class can stay into two separate physical files but when they compile, they compile into one DLL unit.
So now, you have one physical file where you have the VS generated code and in the other physical file, the developer can contain custom coding and after compiling, both these files merge into one DLL.
When we look at Java, they do not have such kind of RAD approach. So there are no partial classes, no code behind, etc. With full respect, I personally love the idea of partial classes when it comes to RAD and Visual programming.
Some months ago, I just wrote a consolidated article where partial classes are useful, 4 real time use of C# partial classes.
Also below is a simple C# partial classes video created by www.questpond.com team. It talks about the importance of partial classes and partial methods.