comp.lang.ada
 help / color / mirror / Atom feed
From: Andy <andy@nospam.com.tj>
Subject: Re: Objects properties -  Ada design issues question
Date: 2000/02/10
Date: 2000-02-09T13:09:41+00:00	[thread overview]
Message-ID: <38A17538.34F0@nospam.com.tj> (raw)
In-Reply-To: s9t9quighse159@corp.supernews.com

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




  reply	other threads:[~2000-02-10  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-04  0:00 Objects properties - Ada design issues question Vladimir Olensky
2000-02-04  0:00 ` Matthew Heaney
2000-02-04  0:00 ` Florian Weimer
2000-02-04  0:00   ` Vladimir Olensky
2000-02-06  0:00     ` Andy
2000-02-07  0:00       ` Vladimir Olensky
2000-02-10  0:00         ` Andy [this message]
2000-02-08  0:00     ` Florian Weimer
2000-02-04  0:00   ` Vladimir Olensky
2000-02-04  0:00   ` Samuel T. Harris
2000-02-04  0:00 ` Vladimir Olensky
replies disabled

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