comp.lang.ada
 help / color / mirror / Atom feed
From: slos <new.stephane.los@gmail.com>
Subject: Re: Polymorphism
Date: Thu, 7 May 2015 01:32:28 -0700 (PDT)
Date: 2015-05-07T01:32:28-07:00	[thread overview]
Message-ID: <21182bbe-e085-446c-9d89-32c3c263094a@googlegroups.com> (raw)
In-Reply-To: <lysib8zw0i.fsf@pushface.org>

Le jeudi 7 mai 2015 09:28:46 UTC+2, Simon Wright a écrit :
> slos writes:
> 
> > I'd like function Object.Area to stay private but the compiler doesn't
> > see it like that and complains if I try to move it in the private
> > part.
> 
> If you do that, the compiler says
> 
> slos.ada:24:13: this primitive operation is declared too late
> slos.ada:24:13: abstract subprograms must be visible (RM 3.9.3(10))
> 
> The reason for this is that derived types wouldn't know that they needed
> to implement the abstract operations.
> 
> If you make the private subprogram concrete,
> 
>    function Area (O : Instance) return Float
>      is (raise Program_Error with "Area not implemented");
> 
> then Circle.Area isn't overriding (because Object.Area isn't visible).
> 
> If you make Circle a child of Object (package Object.Circle), all is
> OK. This is of curse rather restrictive; it depends on who you want to
> be able to derive from Object.Instance.
> 
> 
> The workround I adopted in a similar situation was to comment the
> subprograms that had to be visible with "private use only". I think now
> I would make the names obviously logically private
> (e.g. "Private_Area").

Thank you for your answer Simon.

I have found this suitable for my needs :

> If you make Circle a child of Object (package Object.Circle), all is
> OK. This is of curse rather restrictive; it depends on who you want to
> be able to derive from Object.Instance.

But I thought about something like a private inner package or interface may have existed.

BR,
Stéphane


  reply	other threads:[~2015-05-07  8:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-06 23:05 Polymorphism slos
2015-05-07  7:28 ` Polymorphism Simon Wright
2015-05-07  8:32   ` slos [this message]
2015-05-07  7:41 ` Polymorphism Dmitry A. Kazakov
2015-05-07  8:34   ` Polymorphism slos
2015-05-07 19:09   ` Polymorphism Randy Brukardt
2015-05-11 22:05     ` Polymorphism slos
2015-05-12  1:29       ` Polymorphism Randy Brukardt
2015-05-14 21:34         ` Polymorphism slos
  -- strict thread matches above, loose matches on Subject: below --
1996-11-25  0:00 polymorphism W. Wesley Groleau (Wes)
replies disabled

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