Thursday, November 04, 2004

VJs Tip Of The Day - November 4th 2004

Whidbey - Partial Classes

In Whidbey it would be possible to split huge class files into multiple parts... The keyword used for that is partial... The same keyword works for struct or an interface... When the assembly is compiled then all these files will be merged into one... This can be usually useful when multiple people have to work on same class or when autogeneration is used...
Due to autogeneration getting more and more popular now days the problem that exits currently is that if you modify any code in autogenerated files then again autogeneration with updates causes loss of the manual changes made... by using partial classes you can seperate the autogenerated and manually coded files...

e.g.
// This is the first file.cs
public partial class SameClass
{
public void AutoGenratedMethod()
{
}
}
// This is the second file.cs
public partial class SameClass
{
public void ManuallyCodedMethod()
{
}
}

PS: Next time you get a speeding citation do not pay it off directly... It is better to appear in the court if possible and explain your scenario, judges are usually understanding and if they do not reduce the fine they will probably reduce the points on your drivers licence... It also gives an implied message that you are concerned about your citation and so are ready to appear in the court... Many US states also provide you with an attorney to fight for you in case you have not hired one... :-)

Kathleen has added below points

Partial classes helps with code generation only in minimilast scenarios.
While it is very important there, derivation will remain the prime mechanism for customization - although not everyone has wandered down that road far enough to realize it.

No comments: