[fpc-pascal] Extending an enumeration
Mark Morgan Lloyd
markMLl.fpc-pascal at telemetry.co.uk
Sun Jul 18 20:56:18 CEST 2010
Jetcheng Chu wrote:
> As far as I know, properties cannot be overridden. However, you could
> consider using subrange types, as the example below shows.
>
> type
> Fruit = (Apple, Banana, Cherry, Orange, Pineapple);
> LimitedFruit = Apple..Cherry;
>
> You can use the full enumeration as the property's type, and then
> restrict its value using a custom property setter.
Yes, I was thinking that. However if the basic class was say a
round-robin scheduler with phases rrQuiescent and rrInitialised and the
descendant was say an HP comms protocol handler with additional phases
hpReceivingPadding, hpReceivedSync and so on it would seem to be
questionable practice to have to define all possible enumerated values
in the basic class.
I suppose one possibility would be to define hpPhase= (hpQuiescent:=
rrQuiescent, ... ) and to forcibly disable some of the runtime type
checking, but it's hardly elegant.
Which suggests that the best way is probably to have separate properties
controlling the phase of execution (i.e. whether the code is properly
initialised) and the state of the protocol or whatever being implemented.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-pascal
mailing list