From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.32.1 with SMTP id e1mr43571567obi.31.1436200524262; Mon, 06 Jul 2015 09:35:24 -0700 (PDT) X-Received: by 10.140.94.166 with SMTP id g35mr360349qge.1.1436200524236; Mon, 06 Jul 2015 09:35:24 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!wf20no788264igc.0!news-out.google.com!w15ni27198qge.0!nntp.google.com!m107no690074qgd.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 6 Jul 2015 09:35:24 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=94.107.233.114; posting-account=6m7axgkAAADBKh082FfZLdYsJ24CXYi5 NNTP-Posting-Host: 94.107.233.114 References: <0ade6abf-34c0-46e2-8bd9-d60a00056321@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <66fa1189-9c51-4290-be53-6f3c40545ce7@googlegroups.com> Subject: Re: Declaring constants for a abstract tagged type and concrete sub classes From: Serge Robyns Injection-Date: Mon, 06 Jul 2015 16:35:24 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:26648 Date: 2015-07-06T09:35:24-07:00 List-Id: On Monday, 6 July 2015 17:42:10 UTC+2, Simon Wright wrote: > Serge Robyns <> writes: >=20 > > package Abstract_Root is > > type T_Root is abstract tagged with private; > > procedure Set_XYZ (Self: in out T_Root; ABC : in Integer); > > function Get_XYZ (Self: in T_Root) return Integer; > > private > > type T_Root is abstract tagged record > > XYZ : Integer; > > end record; > > end Abstract_Root; >=20 > > package Concrete is > > type T_Concrete is new T_Root with private; > > No_Element : constant T_Concrete; > > .... > > private > > type T_Concrete is new T_Root with record > > ... > > end record; > > No_Element : constant T_Concrete :=3D (Abstract_Root.No_Element, ...= ); > > end Concrete; >=20 > You could write >=20 > with Abstract_Root; > package Concrete is > type T_Concrete is new Abstract_Root.T_Root with private; > No_Element : constant T_Concrete; > private > type T_Concrete is new Abstract_Root.T_Root with record > ABC : Integer; > end record; > No_Element : constant T_Concrete > :=3D (Abstract_Root.T_Root with ABC =3D> -42); > end Concrete; >=20 > (or whatever will suit you) >=20 > but I think you'll have to give T_Root.XYZ an equivalent default value, > or equality won't work. Dear Simon, Thank you, you seem to confirm my understanding of the "correct" way of doi= ng this. I'm actually even wondering how to implement such an assignment for non abs= tract classes with records. For example: type T_Root ... No_Root_Element : T_Root :=3D (a, b, c); type T_Sub is new T_Root .... No_Sub_Element : T_Sub :=3D ( ??? No_Root_Element ???, x, y z); I'm very much doubting a valid Ada Syntax and hence my whole idea is of no = use. The issue is that the root class could end-up with a lot of data and the su= b classes with much less, they are actually special cases of the generic ro= ot class. If this doesn't work well, I'll use the decorator pattern to address this i= ssue, as this seems to be the most applicable one and can be recursive, whi= ch I'll need anyway, because at the very end, I'll use decorators to create= more specialized instances of the previous one. Regards, Serge