Class Member Visibility Levels

From The Oxygene Language Wiki

Jump to:navigation, search

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



Class Member Visibility Levels determine the scope of class members. For ease of maintenance you should always keep visibility reduced as much as possible. The following levels are available:

Visibility

Access
Rights

private

Truly private, access only from within this very class (same as "private" in C#, but stricter then "private" in classic Object Pascal).

protected

Truly protected; access only from descendants.

public

Accessible by anyone from anywhere.

assembly and protected

Only accessible from descendants implemented in the same assembly. Outside code has no chance of ever accessing this. Use this for code your own descendants need to access, but user's code should not.

assembly or protected

Publicly accessible from anywhere within the same assembly. Outside of the assembly, only accessible from descendants.

assembly

Accessible anywhere in the same assembly. Not accessible from the outside.


These visibility levels also apply to all types, classes, records, interfaces, enums, delegates, sets etc.


Any types used in non-assembly (i.e. public, protected, assembly and protected, assembly or protected) members of other public types must also be public. For example:

type
  Foo = public class
  public
    method Test: Bar;
  end;

Then "Bar" may not be assembly, either (but could be if Foo was assembly or if Test was private or assembly). The default visibility level is assembly.

Overriding Visibility Levels

When overriding members, visibility can be increased, but not decreased.

For example, a property that's protected in the base class might be made public in the ancestor class, but not vice versa. If visibility were allowed to be decreased, this would break polymorphism.

Since you cannot have a method override another method with a lower visibility, these are the levels:

Level Visibility

Level
Specifier
1 Private
2 Assembly and Protected
3 Assembly
3 Protected
4 Assembly or Protected
5 Public

Assembly and Protected are both at level 3 because you can't go from protected to assembly or vice versa.


See Also


Oxygene-48.png

Area: Oxygene Language
Compiler version: Oxygene 5

Language GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox