Menu

keywords-abstract

Will Pittenger

Overview

This keyword is used in two contexts: To mark a class as abstract and to mark a method or property in that class as abstract. Abstract classes are allowed to have virtual functions that they implement or override. However, generally, they will have at least one abstract method or property. Such methods or properties don't have an implementation in the class being declared. Rather, it's up to a derived class to implement those methods and/or properties. An abstract class can't be instantiated as is. You need to derive first and instantiate that. Abstract methods and properties can't be private. Structures can't be abstract as they lack virtual method tablets.

The class declaration

[(\abstract\ | \static\)] \class\ /identifier/
  [\extends\ /baseTypeList/]
  [\implements\ /interfaceList/]

/identifier/ must be a valid identifier. /baseTypeList/ must be a comma delimited list of types to derive from. Leave that clause out if you only need Object as a base type. /interfaceList/ must be a comma delimited list of interfaces that the class will implement (or, given we're talking about an abstract class, require to be to be implemented by derived classes). Omit that clause if you don't need interfaces implemented.

Abstract commands

{(\public\ | \protected\ | \private\) | [(\abstract\ | \virtual\ | \override\)]} \command\  /identifier/ /DeclarationSequence/]
  ' Implement non-abstract commands here

Note: The private keyword is shown, but is incompatible with abstract commands. For more on declaration sequences, see Declaration Sequences.

Abstract functions

This syntax is nearly identical to what's listed above.

{(\public\ | \protected\ | \private\) | [(\abstract\ | \virtual\ | \override\)]} \function\  /identifier/ /DeclarationSequence/]
    returns /TypeDescriptor/
  ' Implement non-abstract commands here

Note: The private keyword is shown, but is incompatible with abstract functions. For more on declaration sequences, see Declaration Sequences. For more on type descriptors, see Type Descriptors.

Abstract complex statements

Note the similarities to the syntax needed for a complex statement delegate. This is the only abstract method type where the syntax differs from that of a normal method. Note that the private access qualifier keyword isn't an option.

(\public\ | \protected\) \abstract\ \statement\ /identifier/ /DeclarationSequence/
  \instructions\ [/TypeDescriptorList/]

For more on declaration sequences, see Declaration Sequences. /TypeDescriptorList/, if present, must be a comma delimited list of type descriptors. For more on type descriptors, see Type Descriptors.

Abstract properties

If you want each accessor declared by a property to be abstract, make the property itself abstract. Note: Nothing prevents derived classes from providing accessors not declared by a base type, abstract or otherwise.

{(\public\ | \protected\ | \private\) | [(\abstract\ | \virtual\ | \override\)]} \property\ /TypeDescriptor/ /identifier/ [\]/DeclarationSequence/\]\]
  ' Put accessors here

Note: The private keyword is shown, but is incompatible with abstract properties. For more on declaration sequences, see Declaration Sequences. For more on type descriptors, see Type Descriptors. This sample includes the portion needed for an indexed property.

Abstract property accessors

There may be some circumstances where you want to provide a get access implementation, but not the set accessor implementation or vice versa. ASIL allows this. In fact, you can make one non-virtual if you need to. The following sample would go inside a property declaration. If the abstract and virtual keywords are both missing from an accessor, it defaults to the modifiers applied to the property itself.

{(\public\ | \protected\ | \private\) | [(\abstract\ | \virtual\ | \override\)]} (\get\ | \set\)
  ' Implement non-abstract accessors here

Note: The private keyword is shown, but is incompatible with abstract property accessors. For more on declaration sequences, see Declaration Sequences.


Related

Wiki: Appendices-Terms-Type descriptors
Wiki: Enums
Wiki: Keywords
Wiki: Type casts
Wiki: keywords-const
Wiki: keywords-constructor
Wiki: keywords-enum
Wiki: keywords-get
Wiki: keywords-new
Wiki: keywords-override
Wiki: keywords-property
Wiki: keywords-set
Wiki: keywords-static
Wiki: keywords-virtual