Structure of an Oxygene Code File
All the code in an Oxygene project is divided into code files. A code file can contain a single class (often recommended) or more than one class or auxiliary type. By default, all types defined in a code file are members of the same Namespace; that namespace is specified at the top of the file via the
Multiple files, or even multiple projects, can of course contribute to the same namespace – in fact, for small to medium projects, it will be common for all types to be situated in the project's one and only namespace. You can read more about this in the Namespace and Uses topic.
Classic Interface/Implementation Split
namespace declaration, traditionally each code file is divided into two parts, the
interface and the
The interface section is similar to the separate header file found in many languages from the C family. It defines the public interface of the code found in that code file, including Types and their Members' signatures.
The implementation section contains the actual, well, implementation. This includes code that implements the classes defined in the interface section. The implementation section provides a level of encapsulation of the complexity of the implemented code.
The advantage of this separation is that it provides a convenient human- and computer-readable summary of the APIs in the code file. This speeds up human navigation and comprehension of the types when consuming the classes elsewhere.
Types can be defined in the implementation section as well, but that makes them private to the file and inaccessible from rest of the project (similar to
unit level Visibility).
Both the interface and the implementation sections may include a
uses clause that can bring additional namespaces "into scope".
uses clauses are covered in more detail in the Namespace and Uses topic
namespace LutherCorp.WorldDomination; interface uses LutherCorp.DominationTools; type WorldDominator = class public method AchieveWorldDomination; end; implementation method WorldDominator.AchieveWorldDomination; begin // Do something end; end.
The end of every code file is indicated with the
end keyword followed by a period. Everything beyond that point will be ignored.
Unified Class Syntax
Oxygene also supports declaring and implementing types in a more unified syntax, where the body of a Method can be directly attached to its declaration. This provides a code layout that is more similar to modern C derivatives such C# or Swift.
There are advantages and drawbacks to both code-styles, and Oxygene does not enforce a struct choice; the two styles can me mixed, with some methods having their implementation at the top, and others being deferred in classic style to the
implementation section of a file contains no code, both the
interface and the
implementation keywords can be omitted:
namespace LutherCorp.WorldDomination; uses LutherCorp.DominationTools; type WorldDominator = class public method AchieveWorldDomination; begin // Do something end; end; end; end.
Again the end of the code file is indicated with the
end keyword followed by a period, and everything beyond that point will be ignored.