Partial Classes

From RemObjects Software

Jump to: navigation, search

This is a Oxygene Language Feature topic
Feel free to add your notes to this topic below.



The definition of a class can be split over two or more files, each containing:

type
  MyClass = partial class
    ...
  end;

Each file defines a separate part of the class. Repeating the same element (e.g. methods with an identical signature) in several files causes an error. If ancestors (classes or interfaces) are specified, the list does not need to match in all files.


Consider the following:

type
  Foo = partial class(MyBase, ISomething);
  end;
...
  Foo = partial class(ISomethingElse);
  end;

Foo will now descend from MyBase, and implement both interfaces. However the "public, sealed, abstract" keys must match in all files.

This facility is particularly useful for systems that generate (and regenerate) code automatically - it allows user methods to be separated from the code which the user does not need to see.


C# introduced this feature in version 2.0 and its form designer no longer mixes "designer generated code" with the main code - the form class is split into two files, one for user code and one for the generated code.


Other applications might split an overly complex class into several files. For example, it could be useful to keep an interface implementation separate from the rest of the code or even split a class into two to allow two developers to work on it simultaneously.


See Also


Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0 Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)

GlossaryKeywordsLanguage FeaturesPlatform FeaturesSamplesArticlesHow ToIssues

Personal tools