mustBeOverridden top-level constant
_MustBeOverridden
const mustBeOverridden
Used to annotate an instance member m
declared on a class or mixin C
.
Indicates that every concrete subclass of C
must directly override m
.
The intention of this annotation is to "re-abtract" a member that was previously concrete, and to ensure that subclasses provide their own implementation of the member. For example:
base class Entity {
@mustBeOverridden
String toString();
}
abstract class AbstractEntity extends Entity {
// OK: AbstractEntity is abstract.
}
sealed class SealedEntity extends Entity {
// OK: SealedEntity is sealed, which implies abstract.
}
mixin MixinEntity on Entity {
// OK: MixinEntity is abstract.
}
class Person extends Entity {
// ERROR: Missing new implementation of 'toString'.
}
class Animal extends Entity {
// OK: Animal provides its own implementation of 'toString'.
String toString() => 'Animal';
}
This annotation places no restrictions on the overriding members. In particular, it does not require that the overriding members invoke the overridden member. The annotation mustCallSuper can be used to add that requirement.
Tools, such as the analyzer, can provide feedback if
- the annotation is associated with anything other than an instance member (a method, operator, field, getter, or setter) of a class or of a mixin, or
- the annotation is associated with a member
m
in class or mixinC
, and there is a concrete classD
which is a subclass ofC
(directly or indirectly), andD
does not directly declare a concrete override ofm
and does not directly declare a concrete override ofnoSuchMethod
.
Implementation
const _MustBeOverridden mustBeOverridden = _MustBeOverridden();