Click here to Skip to main content
15,881,455 members
Articles / Programming Languages / C#

Why Microsoft has partial classes and Java does not?

Rate me:
Please Sign up or sign in to vote.
3.50/5 (27 votes)
18 Sep 2014CPOL2 min read 76.3K   13   32
In this article we have explained Why Microsoft has partial classes and Java does not have it and how new era of RAD (Rapid application development) and visual programming started.

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 dir, edit, mkdir, etc.

Image 1

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:

  • One is auto-generated by the tool where developers drag and drop UI elements like button, text boxes. These kinds of codes are marked with standard Microsoft comments like something below. They expect developers to not touch it as it would lead to undesirable effects.
    ”cs”
    //---------------------------------------------------------------------------
    // <auto-generated>
    //    This code was generated from a template.
    //
    //    Manual changes to this file may cause unexpected behavior in your application.
    //    Manual changes to this file will be overwritten if the code is regenerated.
    // </auto-generated>
    //---------------------------------------------------------------------------
    
    using System;
    using System.Data.Objects;
    using System.Data.Objects.DataClasses;
    using System.Data.EntityClient;
    using System.ComponentModel;
    using System.Xml.Serialization;
    using System.Runtime.Serialization;
  • Second is the custom code which developers need to write to fulfill business functionality. This code is not auto-generated and very custom code which developers write for specific needs.

Image 2

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.

Image 3

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.

Image 4

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Just Compile
India India
Learning is fun but teaching is awesome.

Who I am? Trainer + consultant + Developer/Architect + Director of Just Compile

My Company - Just Compile

I can be seen in, @sukeshmarla or Facebook

Comments and Discussions

 
GeneralMy vote of 5 Pin
xszhu20-Sep-17 14:47
xszhu20-Sep-17 14:47 
GeneralMy vote of 5 Pin
User97022-Jan-15 0:20
User97022-Jan-15 0:20 
GeneralMy vote of 1 Pin
TSchind29-Sep-14 22:04
TSchind29-Sep-14 22:04 
GeneralMy vote of 1 Pin
Howard Richards22-Sep-14 2:52
Howard Richards22-Sep-14 2:52 
GeneralMy vote of 1 Pin
Richard MacCutchan22-Sep-14 0:16
mveRichard MacCutchan22-Sep-14 0:16 
News[My vote of 1] Too much M$ PR campaigning Pin
Chad3F20-Sep-14 20:15
Chad3F20-Sep-14 20:15 
GeneralMy vote of 2 Pin
vytheese19-Sep-14 5:42
professionalvytheese19-Sep-14 5:42 
QuestionDelphi Pin
Black68cougar19-Sep-14 4:40
Black68cougar19-Sep-14 4:40 
GeneralMy vote of 2 Pin
Nikhil Shekhar19-Sep-14 4:25
Nikhil Shekhar19-Sep-14 4:25 
GeneralMy vote of 1 Pin
Emile van Gerwen18-Sep-14 22:20
Emile van Gerwen18-Sep-14 22:20 
QuestionShallow Pin
Member 1082963818-Sep-14 8:29
Member 1082963818-Sep-14 8:29 
GeneralMy vote of 2 Pin
tornbladswe18-Sep-14 2:35
tornbladswe18-Sep-14 2:35 
QuestionSorry, not quite true Pin
Member 188040318-Sep-14 2:18
Member 188040318-Sep-14 2:18 
AnswerRe: Sorry, not quite true Pin
tornbladswe18-Sep-14 2:34
tornbladswe18-Sep-14 2:34 
AnswerRe: Sorry, not quite true Pin
Shivprasad koirala18-Sep-14 14:11
Shivprasad koirala18-Sep-14 14:11 
GeneralMy vote of 1 Pin
Member 188040318-Sep-14 2:16
Member 188040318-Sep-14 2:16 
GeneralRe: My vote of 1 Pin
Shivprasad koirala18-Sep-14 14:14
Shivprasad koirala18-Sep-14 14:14 
Like ???
My book .NET interview questions with 500 mostly asked questions in .NET world .NET Interview questions and answers


modified 18-Sep-14 20:52pm.

GeneralMy vote of 3 Pin
Stanley Gillmer18-Sep-14 0:37
Stanley Gillmer18-Sep-14 0:37 
QuestionIMO Pin
Dewey17-Sep-14 6:07
Dewey17-Sep-14 6:07 
GeneralInteresting. Pin
ugo.marchesini17-Sep-14 4:47
professionalugo.marchesini17-Sep-14 4:47 
QuestionWhy Java does not have partial classes? Pin
Paulo Zemek17-Sep-14 3:51
mvaPaulo Zemek17-Sep-14 3:51 
AnswerRe: Why Java does not have partial classes? Pin
Dewey17-Sep-14 6:08
Dewey17-Sep-14 6:08 
GeneralRe: Why Java does not have partial classes? Pin
Paulo Zemek17-Sep-14 6:12
mvaPaulo Zemek17-Sep-14 6:12 
GeneralRe: Why Java does not have partial classes? Pin
Dewey20-Sep-14 1:19
Dewey20-Sep-14 1:19 
QuestionNot just UI Pin
Duncan Edwards Jones17-Sep-14 3:16
professionalDuncan Edwards Jones17-Sep-14 3:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.