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.91.6 with SMTP id ca6mr69024002obb.29.1436177422905; Mon, 06 Jul 2015 03:10:22 -0700 (PDT) X-Received: by 10.140.106.247 with SMTP id e110mr433498qgf.7.1436177422875; Mon, 06 Jul 2015 03:10:22 -0700 (PDT) Path: buffer2.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.glorb.com!wf20no532843igc.0!news-out.google.com!4ni64994qgh.1!nntp.google.com!w90no891119qge.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 6 Jul 2015 03:10:22 -0700 (PDT) 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 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0ade6abf-34c0-46e2-8bd9-d60a00056321@googlegroups.com> Subject: Declaring constants for a abstract tagged type and concrete sub classes From: Serge Robyns Injection-Date: Mon, 06 Jul 2015 10:10:22 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.giganews.com comp.lang.ada:193937 Date: 2015-07-06T03:10:22-07:00 List-Id: Hi, I'm new on Ada OO-programming and I'm facing this dilemma on a class hierar= chy. The idea is to have a root type with some common data parts and common inte= rface and some concrete procedures and functions but to force to have real = variables through subclasses. As such I've therefore the following (using Get/Set as examples only): 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; As I want this class hierarchy to be usable without access type is was plan= ning to define No_Element constants. However, the compiler refuses me to c= reate constant variables, as the type is abstract. This isn't a problem wh= en the record has only a few components, but when there are a lot it is pai= nful, as I was "hoping" to use the No_Element as a part of the No_Element o= f the subclasses. This idea came from the Ada Containers. And to be able = to use No_Element in if statements like Something along: =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; and then: A_Concrete : T_Concrete; ... A_Concrete :=3D A_List.Find (Expression); -- A_List could be a complex object with multiple components, -- including T_Concrete. if A_Concrete =3D No_Element then -- some error handling end if; Any advise on how to handle this need in Ada? I'll face this issue too in = a few potential design patters I want to use (Proxy for example). Moreover= , this constant allows me to initialize variables at the moment of my choic= e; Regards, Serge