[fpc-devel] class abstract, class sealed implementation. please review.
Alexander Klenin
klenin at gmail.com
Sat Oct 17 01:13:03 CEST 2009
On Sat, Oct 17, 2009 at 08:06, Graeme Geldenhuys
<graemeg.lists at gmail.com> wrote:
> 2009/10/16 Alexander Klenin <klenin at gmail.com>:
>> "Class sealing allows extension of classes within a package, but
>> prevent clients from extending such classes outside of the package."
>> This might actually make some sense, see e.g. TBasicChartSeries class
>> in TAChart package.
>
> As I said in my earlier reply. I don't see the point of sealed class.
> Why would you want to limit the use of a class. It goes against the
> OOP principals. One developer cannot think of all possible uses for a
> class, so why limit other developers that could see other uses or
> extensions.
Well, I did point out that the feature is controversial.
You can read some arguments supporting sealed classes in the paper I cited.
It should be noted that most compelling of these arguments are based on the fact
that Java can enforce member access at runtime, so private members and
sealed classes are useful as security devices.
Since FPC will never be able to do that, this use-case for sealed classes moot.
However, the paragraph you quoted was intended to illustrate very
different use case
(see TBasicChartSeries class definition and documentation):
prohibit the client code from inheriting base class, while allowing
to inherit it's decendants.
I.e. in TAChart, we have this chain of inheritance:
TBasicChartSeries -> TCustomChartSeries -> TChartSeries ->
TBasicPointtSeries ->TLineSeries.
Of these, TBasicChartSeries and TBasicPointSeries classes are
implementation details used to reduce code duplication,
their interface subject to change without notice.
So it would be useful to explicitly prohibit inheriting them outside
of TAChart code.
Of course, inheriting other classes should still be allowed.
So, how about this semantic (which nicely mirrors "private" access specifier):
"sealed" class attribute prevents inheriting from sealed class by the classes
outside of the unit containig that class.
--
Alexander S. Klenin
More information about the fpc-devel
mailing list