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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,248f80acc3d5ccb3 X-Google-Attributes: gid103376,public From: Andy Subject: Re: Objects properties - Ada design issues question Date: 2000/02/10 Message-ID: <38A17538.34F0@nospam.com.tj>#1/1 X-Deja-AN: 583641179 Cache-Post-Path: news.ozonline.com.au!unknown@melb-pool-171.ozonline.com.au Content-Transfer-Encoding: 7bit References: <877lgklryd.fsf@deneb.cygnus.argh.org> <389CEEF8.69E7@nospam.com.tj> Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@connect.com.au X-Trace: perki.connect.com.au 950101781 14308 203.4.248.42 (9 Feb 2000 13:09:41 GMT) Organization: Australia On Line Pty Ltd Mime-Version: 1.0 Reply-To: andy@nospam.com.tj NNTP-Posting-Date: 9 Feb 2000 13:09:41 GMT Newsgroups: comp.lang.ada Date: 2000-02-09T13:09:41+00:00 List-Id: Vladimir Olensky wrote: > > Adding new fields to the derived [tagged] record type and > adding new public operations to work with these fields is > not the same. In Ada one need to do both. I don't think so. package X is type X is tagged .....; end X; with X; package Y is type Y is X.X with record Attribute : Some_New_Attriutes; end record; end Y; with Y; package Z is type Z is new Y.Y with null record; procedure M1 (Item : in Z); end Z; This is legal Ada. Package Y extends X by just adding fields. Package Z extends Y by just adding new public methods. > The "common interface" is a common set of operations. > Our intent is not to add any new operations to the public > part of the interface even if we add some new properties > to the derived classes. What we want is only pair of Get > and Set operations for any property that could be declared > in any derived class. These pair of Get and Set operations > may be hidden and be used to overload implicitly ":=" operator > as done in Delphi or they may be visible to clients and be > declared in the common root interface. > The idea is that we have only one pair of Get and Set operations > for any kind of property that we may have in the future. > And this means that we have common interface to any kind > of property that we do not know in advance. > [snipped] > But again as I mentioned in my previous posts all that could be > expressed using current Ada representation syntax: > > package P is > type Some_Tagged_Type is tagged record > Property1 : Some_Type; > <...> > end record; > private > for Some_Tagged_Type.Property1'Read use Some_Function ... ; > for Some_Tagged_Type.Property1'Write use Some_Procedure ... ; > end P; > > We do not even have a need to use "property" keyword. > If for some field exists such representation clause that means that > this is a property field. > Of course use of "property" modifier could make everything more clear > for the client of that package. > But even if Ada allowed this, how can you address a new Property by name on a child class, if you want to restrict yourself to the common (parent) interface??? > >As to your original question. One models Delphi properties with Get and > >Set operations. Although syntacically different, they provide > >essentially the same operation. > > As I explained above in Ada we can not do that without introducing new > operations with new names into public interface as Ada does not allow > to overload operators for the fields of [tagged] records (only for types). > On the other hand in Delphi one need to overloads READ and (or) WRITE > operations for any class field that is declared as property using syntax > surprisingly close to Ada syntax. > In the public interface these READ and WRITE operations implicitly > overload common ":=" operator. If I read you write, you want the Ada equivilent of this Delphi: type Root = class private function Get : Integer; virtual; public; property X : Integer read Get; end; Child = class (Root) private function Get : Integer; override; end; var A : Root; B : Root; K : Integer; begin A := Root.Create; B := Child.Create; K := A.X; // this calls the Get function in Root. K := B.X; // this calls the Get function in Child. end. If yes, it's easy - read on. If no please elaborate... package Root is type Item is tagged ...; function X (I : in Item) return Integer; end Root; with Root; package Child is type Item is tagged ...; function X (I : in Item) return Integer; -- this overrides Root.X end Child; with Root, Child; A : Root.Item'Class := some Root value; B : Root.Item'Class := some Child value; K : Integer; begin K := Root.X (A); -- this calls the X 'property' function in Root K := Root.X (B); -- this calls the X 'property' function in Child end; Regards, Andy