comp.lang.ada
 help / color / mirror / Atom feed
From: Optikos <ZUERCHER_Andreas@outlook.com>
Subject: Re: How to stop inheritance in a good way?
Date: Fri, 17 Jan 2020 13:17:38 -0800 (PST)
Date: 2020-01-17T13:17:38-08:00	[thread overview]
Message-ID: <7b7ecd25-b3e0-44d8-92a9-0373496e212b@googlegroups.com> (raw)
In-Reply-To: <bf6ad174-4314-4062-aaf7-f4af70504238@googlegroups.com>

On Friday, January 17, 2020 at 3:48:02 AM UTC-6, reinert wrote:
> Seems like I end up in a mess if I try to avoid such inheritance :-)
> 
> Maybe better to try to stick properly with the OOP dogmas and shape up the concepts.

Perhaps you should describe •why• you want to elide function B from object2_2_t so decisively & firmly.  Most commenters on this posting are perplexed by why you would want polymorphism via object1_t'Class that is permitted to invoke B in the object2_1_t situation but is prohibited at compile-time* from invoking B in the object2_2_t situation, such as a heterogenous mixture of instances of object2_1_t and of object2_2_t.  You should describe the intended usage in package bodies more (and let the package specifications be rather unrestricted degree[s] of freedom to match your intended usage).  Indeed, doing so might lead you yourself to the solution as you refine your thinking; we'd be interested in seeing your solution to your rejiggered problem-statement even if you solve it yourself.

* which seems to be reinert's stated desire, not throwing an exception at run-time

Because we cannot completely see the intended usage in the package bodies and what precisely needs to be prohibited at compile-time and where, we cannot really present a detailed solution, nor discuss intermediate to advanced topics such as invariance, covariance, contravariance, and bivariance (not all of which are supported by Ada directly or by emulation).

Conversely, I have seen such defeat-the-isa-contract questions arise perennially in multiple OO programming languages for decades, so this is in the ballpark of some question that deserves a no-no don't do that do this instead style of answer.  Usually the answer to a similar question touches on 1 or more of:  covariance, contravariance, declaration-site variance annotations, and/or usage-site variance annotations (or in the case of C++, dangerous techniques and/or various forms of type casting and/or slicing aberrant behavior).

One solution could be that invoking object2_2_t's B is not a compile-time error (and not a raised exception either) but rather simply a do-nothing no-op in the object2_2_t case when invoked polymorphically via object1_t'Class.  This would be an application of the no-harm-no-foul principle.  But we cannot see whether this elision at run-time fits with reinert's intended usage throughout package bodies.


  reply	other threads:[~2020-01-17 21:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-15  8:32 How to stop inheritance in a good way? reinert
2020-01-15  9:08 ` Dmitry A. Kazakov
2020-01-15 20:56 ` Randy Brukardt
2020-01-15 23:19 ` Jere
2020-01-17  9:48   ` reinert
2020-01-17 21:17     ` Optikos [this message]
2020-01-17 13:39 ` Shark8
2020-01-20  4:32   ` ric.wai88
2020-01-17 16:56 ` AdaMagica
2020-01-17 23:51   ` Jeffrey R. Carter
replies disabled

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