Class (computer programming)#Partial

A partial class is a term used in object-oriented programming and describes a procedure to divide classes into multiple source code files, or to declare at various locations within a file.

  • Increase the readability in very large classes.
  • Different developers can work on the same class without interfering with each other.
  • Separation of interface and class definition or from public and private sectors.
  • Separation of concerns, similar in aspect-oriented programming. ( 1)
  • Separation of automatically generated code of a code generator and manually -written by man code. The generated code can be easily updated at any time without having to disturb the two bodies against each other.

Separation of Concerns

Partial classes also support separation of concerns. The following C # example shows a class Bear, which has various aspects. These are implemented in multiple files.

Public partial class Bear {     private IEdible Hunt ( )     {         / / Returns food ...     } } Bear_Eating.cs public partial class Bear {     private int Eat ( IEdible food)     {         return food.Nutrition.Value;     } } Bear_Hunger.cs public partial class Bear {     private int hungry;       public void monitor Hunger ( )     {          / / At this point we refer to methods that are defined in the other partial classes          if ( hungry > 50)              Hunger - = this.Eat ( this.Hunt ());     } } By using partial classes, it is very easy to extend possible program properties by adding source code files by extra files are compiled. There may be features that are offered to a customer at an additional cost, for example,.

  • Object-Oriented Programming
634977
de