comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Extension of non-limited type needs limited component
Date: Fri, 15 Nov 2002 21:56:30 GMT
Date: 2002-11-15T21:56:30+00:00	[thread overview]
Message-ID: <wccfzu28pkh.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: gmh9tusk16le4p3s31c51r6al8pjbspb8n@4ax.com

Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> writes:

> On Fri, 15 Nov 2002 00:30:03 GMT, Robert A Duff
> <bobduff@shell01.TheWorld.com> wrote:
> 
> >Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> writes:

> Sure? And what about this:
> 
> type A is tagged ...
> procedure Foo (L, R : A);
> 
> type B is new A with ....
> 
> X : A'Class := Some_A;
> Y : A'Class := Some_B;
> 
> Foo (X, Y); -- Oops, dispatching to nowhere!

True.  But I'm not happy about it.  And it doesn't mean single-argument
dispatching should be made more dangerous to match double-arg
dispatching.  ;-)

> [ Not that I argue for SmallTalk, of course (:-)) ]

;-)

> Then disallowing is already allowed for non-tagged types =
> "is abstract". 
> 
> Further one can always override with a subroutine that throws
> Program_Error. Is that better? IMO it is the same.

Yes, it is the same.  I see no reason to add special syntax to make it
easy, though.

Note that Java more-or-less prevents this problem by making exceptions
part of the visible contract.  I think they got some of the details
wrong, but they are on the right track.  The Java rules are a pain,
but I think they could be modified to make them work nicely.

>... The only real
> difference is that one cannot get rid of overloading of the undesired
> operation. What is actually required. I think that there could be
> situations where it would be useful to disallow an operation in the
> public interface and to override it with something working in the
> private one.

Hmm.  What example?  It seems to me that hiding/disallowing the
operation for the derived type is dishonest, because a client can always
call that operation by converting to the parent type 'Class and
dispatching.

Note that you can say:

    type T is new A with private;
    ...
    type T is new B with record...

where B is derived from A, and has more operations.
This is a useful capability, and is similar to what you asked for above.
The "more operations" are visible only inside T package.
Clients can't convert to B, because they can't see that T is "really"
derived from B.

Here's an idea I've been thinking about for some years, which might
address your desire to "take away" operations:
Define two kinds of inheritance, "is a" inheritance, and "is like a"
inheritance.  When you use "is a" inheritance, you can only *add*
operations, and you can convert to the parent type.  When you use "is
like a" inheritance, you can also take away operations, but you are
forbidden from converting to the parent type.  With "is like a"
inheritance, you are defining a new abstraction that is similar to
the parent, but you don't claim that it "is a" parent, and you don't
want to view the new type *as* a parent.  What do you think?

- Bob



  reply	other threads:[~2002-11-15 21:56 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-13 10:03 Extension of non-limited type needs limited component Mike
2002-11-13 12:06 ` Jean-Pierre Rosen
2002-11-14  9:26   ` Mike
2002-11-14 11:43     ` David C. Hoos, Sr.
2002-11-14 12:33     ` Jean-Pierre Rosen
2002-11-14 14:27       ` Dmitry A. Kazakov
2002-11-14 19:25         ` Randy Brukardt
2002-11-15 10:04           ` Dmitry A. Kazakov
2002-11-15 22:09             ` Robert A Duff
2002-11-16 12:39               ` Dmitry A. Kazakov
2002-11-16 16:15                 ` Robert A Duff
2002-11-17 11:14                   ` Dmitry A. Kazakov
2002-11-17 12:26               ` Dale Stanbrough
2002-11-18 20:33                 ` Randy Brukardt
2002-11-18 21:48               ` Eric
2002-11-19 14:38               ` Eric
2002-11-15 21:41           ` Robert A Duff
2002-11-16  3:54             ` Randy Brukardt
2002-11-15  0:30         ` Robert A Duff
2002-11-15 10:22           ` Dmitry A. Kazakov
2002-11-15 21:56             ` Robert A Duff [this message]
2002-11-16 12:39               ` Dmitry A. Kazakov
2002-11-14 23:39     ` Robert A Duff
2002-11-15 21:51       ` Mike
2002-11-13 14:28 ` Robert A Duff
2002-11-14  9:33   ` Mike
2002-11-14  9:35     ` Lutz Donnerhacke
2002-11-14 21:41     ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
2002-11-15 10:47 Grein, Christoph
2002-11-15 12:12 ` Dmitry A. Kazakov
2002-11-15 13:29   ` Jean-Pierre Rosen
2002-11-15 14:34     ` Dmitry A. Kazakov
2002-11-15 21:26     ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox