|
Boost : |
From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-01-30 05:13:23
>From: "Gennaro Prota" <gennaro_prota_at_[hidden]>
> On Tue, 28 Jan 2003 10:47:52 -0800, "Andrei Alexandrescu"
> <andrewalex_at_[hidden]> wrote:
>
> >"Peter Dimov" <pdimov_at_[hidden]> wrote in message
> >> While we're at it, is the final verdict that is_base_and_derived<void,
X>
> >> should be false? What about is_base_and_derived<void, void>?
> >
> >Well, clearly void is no base. Even if we also define
is_super_and_subtype,
> >void is hardly a supertype of everything.
>
> Could you please clarify this? You mean:
>
> T is a subtype of U <=> ...?...
>
> T is a supertype of U <=> ...?...
Supertype/subtype is a more general notion than inheritance and
base/derived. The Liskov Substitution Principle states:
"What is wanted here is something like the following substitution property:
If for each object o1 of type S there is an object o2 of type T such that
for all programs P defined in terms of T, the behavior of P is unchanged
when o1 is substituted for o2 then S is a subtype of T."
Notice that it doesn't say anything about "class" or "inheritance",
anywhere. If S = T, LSP still holds. Therefore, as Andrei said it, in
language theory, such as this, a type may be considered its own
supertype/subtype.
Supertype/subtype may also have other forms than inheritance. "short" may be
considered a subtype of "int", for example (the opposite may or may not be
true, depending on if they are of equal size). Likewise, as Kevlin Henney
noted in an article (http://www.cuj.com/experts/1901/henney.htm), a class's
"const" interface may be considered a subtype of the whole interface.
Notice that, as Kevlin notes in the article, for all these cases, LSP is
expected by the language: A derived object or pointer/reference is
implicitly converted to a Base object or pointer/reference (but going the
other way requires a cast), short is convertible to int (and vice versa, in
this case), and an object or pointer/reference to an object is implicitly
converted to a const object or pointer/reference (but again, going the other
way requires a cast).
Given that supertype/subtype has such a general meaning, how should an
is_super_and_subtype be defined? I guess the proposal mean to define it in
terms of inheritance, only, and in that case, it would work like
is_base_and_derived, with the addition that a type is its own
supertype/subtype (but not its own base/derived type).
This is also reflected in Loki: SuperSubclass is like is_super_and_subtype,
and SuperSubclassStrict is like is_base_and_derived.
Regards,
Terje
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk