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.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, INVALID_MSGID 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: "Vladimir Olensky" Subject: Re: Objects properties - Ada design issues question Date: 2000/02/07 Message-ID: #1/1 X-Deja-AN: 582603308 References: <877lgklryd.fsf@deneb.cygnus.argh.org> <389CEEF8.69E7@nospam.com.tj> Organization: Posted via Supernews, http://www.supernews.com X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Newsgroups: comp.lang.ada X-Complaints-To: newsabuse@supernews.com Date: 2000-02-07T00:00:00+00:00 List-Id: Andy wrote in message <389CEEF8.69E7@nospam.com.tj>... >Vladimir Olensky wrote: >> >> Problem arises ( as I described in previous message) when we want >> to define common interface to the set of objects ("Black Boxes") derived >> from some root class and we do not know in advance properties for >> particular derived object that should be revealed to the client. In >> addition that properties could be very different for different derived >> classes. >> >> Problem with standard Get and Set approach is that you need to extend >> interface for each derived type and this breaks our intention to have >> common interface with some limited set of operations to each "Black Box" >> component. >> >> So it would be nice to have common interface to different properties >> (that are not known in advance) of different kind of objects. >> So here use of ":=" as a standard Get Set operator for any property >> is very useful. We just define in the private part of the implementation >> what this operator does for each particular property without disturbing >> public interface. >> >But the fact that you would like declare these as properties in a child >class changes the 'common interface'. If a child class has a new >property (as can be done in Delphi) or defines additional Get/Set >operations as is done in Ada 95 - what's the difference. You cannot > access these via the common interface defined for the root class. > >Or am I missing something? 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. 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. In addition to what I have shown in my previous posts Ada have one more construct that could be used to model this common interface to any property. This is use of Read and Write attributes as done in Ada.Streams. So we could just use: Value := Some_Tagged_Type.Property1'Read; Some_Tagged_Type.Property1'Write (Value); All this means that we have at least two ways to do what we want without any change in the current Ada syntax. The only problem that we have now is that Ada allows to overload operators only for types but not for the fields of some [tagged] record types. As a result of this we need to introduce new operations with new names into the public interface of the derived types/classes and this is what I meant when talking about disturbing common public interface. 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. > >As do 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. Regards, Vladimir Olensky