comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: tagged types extensions - language design question
Date: 2000/01/29
Date: 2000-01-29T00:00:00+00:00	[thread overview]
Message-ID: <OWsk4.3504$Sa2.128928@newsread2.prod.itd.earthlink.net> (raw)
In-Reply-To: s94522bcq0s54@corp.supernews.com

In article <s94522bcq0s54@corp.supernews.com> , "Vladimir Olensky" 
<vladimir_olensky@yahoo.com> wrote:

> Two classes  not always equal to two packages.

Yes, I think we agree on this.  My example of this was the
implementation of the Observer pattern.


> Two classes could be in one file or in one enclosing class but two Ada
> packages are different files for which I should invent names.

Not necessarily.  The relationship of packages ("program units") to
files isn't specified by the language.  Some compilers require that they
be in separate files, but not all compilers do.

If you do want to put multiple program units in a single file, then you
can just use gnatchop to automatically create separate files for each
unit.


> Also if I have an abstract root type with private and I extend it to another
> abstract tagged  type with additional private fields and the last one  is a
> parent to two concrete types both of them having the same public attributes
> then I should put that derived types in additional child package and duplicate
> that public attributes in each derived type instead of putting them (public
> attributes)  in the abstract parent class.

If I understand you correctly, I showed how to do this in my last
message.  You do not have to duplicate public attributes.  The
intermediate type in which the public attributes are declared can be
shared among derived types, and without upsetting the "natural" package
hierarchy.


> Also I should duplicate primitive operations on that attributes for each
> derived type instead of defining only one operation in the parent class
> or even at upper level root class.

The primitive operations for the intermediate type can be declared
together with the declaration of the type.  No duplication is necessary.


> Or I should first create intermediate package  in which public attributes are
> added to the abstract parent (name it as Root.Parent.PubAttr) and then in
> the final package to extend that abstract parent with private fields and then
> in the same package I can create non-abstract derived classes. I could not
> tell that it is very convenient.  It would be better to have all this in one
> package.

I'm not sure what you're trying to say here, but it sounds similar the
the example I posted in my last message.

If you're trying to declare public and private attributes, then you're
going to have to declare (abstract) intermediate types.  Yes, this
carries a syntactic burden, but we disagree about its severity.

In any kind of design problem (here, the design of a computer language),
one rule of thumb is "design for the common case."  In other words,
common things should be easy to do.  Don't make the uncommon case easy,
if that means making the common case harder.

As Tucker pointed out, declaring an abstraction with both public and
private attributes is not a common thing to do, and so they didn't
design for that case specifically.  This keeps the language simple.

Yes, as a consequence, in this particular case you have to work a little
harder in order to implement the abstraction, but you can get the job
done.


> class T {
>     protected:  // visible only in the derived classes
>        int s ;
>     public:
>        int x,y;
>        T() { s =2; x=3; y=4;};   // constructor
>  };


package P is

  type T_Public is abstract tagged record
    X : Integer := 3;
    Y : Integer := 4;
  end record;

  type T is new T_Public with private;

private

  type T is new T_Public with record
    S : Integer := 2;
  end record;

end P;




> class T1 :   T {
>      protected:
>         int s1 ;
>     public:
>         int x1,y1;
>         int Calculate ()
>                     {
>                          return (s+s1)*(x+x1+y+y1);
>                      }
>         T1() { s1 =3; x1=6; y1=7;};
>  };

package P.C is

  type T1_Public is abstract new T with record
    X1 : Integer := 6;
    Y1 : Integer := 7;
  end record;

  type T1 is new T1_Public with private;

  function Calculate (O : T1) return Integer;

private

  type T1 is new T1_Public with record
    S1 : Integer := 3;
  end record;

end P.C;


> int main(int argc, char* argv[])
> {
>     int result;
>     T1  P;
>     result = P.Calculate();
>     printf("result is %d \n", result);  // result is 100
>     return 0;
> }

with P.C;  use P.C;
procedure Main is
  O : T1;
  Result : constant Integer := Calculate (O);
begin
  Put_Line ("Result is " & Integer'Image (Result));
end Main;




  parent reply	other threads:[~2000-01-29  0:00 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-27  0:00 tagged types extensions - language design question Vladimir Olensky
2000-01-27  0:00 ` Fraser
2000-01-27  0:00 ` Laurent Guerby
2000-01-28  0:00   ` Vladimir Olensky
2000-01-28  0:00     ` Andy
2000-01-28  0:00       ` Vladimir Olensky
2000-01-29  0:00         ` Andy
2000-01-31  0:00           ` Vladimir Olensky
2000-01-27  0:00 ` Matthew Heaney
2000-01-27  0:00   ` Charles Hixson
2000-01-28  0:00   ` Vladimir Olensky
2000-01-28  0:00     ` Matthew Heaney
2000-01-28  0:00       ` Charles Hixson
2000-01-28  0:00         ` Matthew Heaney
2000-02-01  0:00           ` Charles Hixson
2000-02-01  0:00             ` Matthew Heaney
2000-01-29  0:00       ` Vladimir Olensky
2000-01-29  0:00         ` Matthew Heaney
2000-01-29  0:00         ` Matthew Heaney [this message]
2000-01-31  0:00           ` Vladimir Olensky
2000-01-31  0:00             ` Matthew Heaney
2000-01-31  0:00               ` Vladimir Olensky
2000-01-28  0:00 ` Tucker Taft
2000-01-31  0:00   ` Vladimir Olensky
2000-02-01  0:00   ` Charles Hixson
2000-02-01  0:00     ` Matthew Heaney
2000-02-01  0:00       ` Brian Rogoff
2000-02-03  0:00         ` scripting/extension language for Ada (was : Re: tagged types extensions) root
2000-02-03  0:00           ` Brian Rogoff
2000-02-04  0:00             ` Ray Blaak
2000-02-04  0:00               ` Robert A Duff
2000-02-05  0:00                 ` Ehud Lamm
2000-02-05  0:00                 ` blaak
2000-02-05  0:00                   ` Brian Rogoff
2000-02-09  0:00                   ` Robert A Duff
2000-02-09  0:00                     ` Ted Dennison
2000-02-10  0:00                       ` Samuel T. Harris
2000-02-10  0:00                 ` Pascal Martin
2000-02-10  0:00                   ` Ray Blaak
2000-02-11  0:00                     ` David Starner
2000-02-12  0:00                       ` blaak
2000-02-15  0:00                         ` Brian Rogoff
2000-02-12  0:00                       ` Pascal Martin
2000-02-11  0:00                     ` scripting/extension language for Ada (we have an opportunity here) Tarjei T. Jensen
2000-02-11  0:00                       ` Robert I. Eachus
2000-02-12  0:00                         ` Tarjei Tj�stheim Jensen
2000-02-12  0:00                           ` Samuel T. Harris
2000-02-14  0:00                             ` Robert A Duff
2000-02-15  0:00                               ` Samuel T. Harris
2000-02-16  0:00                                 ` Robert A Duff
2000-02-16  0:00                                   ` Samuel T. Harris
2000-02-16  0:00                                     ` Robert A Duff
2000-02-17  0:00                                       ` Samuel T. Harris
2000-02-12  0:00                           ` root
2000-02-12  0:00                         ` Pascal Martin
2000-02-13  0:00                           ` Robert I. Eachus
2000-02-16  0:00                             ` scripting/extension ... [off topic] Nick Roberts
2000-02-16  0:00                               ` Ray Blaak
2000-02-12  0:00                         ` scripting/extension language for Ada (we have an opportunity here) Samuel T. Harris
2000-02-12  0:00                         ` blaak
2000-02-14  0:00                     ` scripting/extension language for Ada (was : Re: tagged types extensions) Robert A Duff
2000-02-04  0:00               ` Stanley R. Allen
2000-02-04  0:00                 ` Samuel T. Harris
2000-02-05  0:00                   ` Lionel Draghi
2000-02-05  0:00                     ` Samuel T. Harris
2000-02-06  0:00                       ` Lionel Draghi
2000-02-06  0:00                       ` Bryce Bardin
2000-02-08  0:00                         ` Samuel T. Harris
2000-02-05  0:00                 ` Lionel Draghi
2000-02-05  0:00                 ` Ray Blaak
2000-02-05  0:00             ` scripting/extension language for Ada (was : Re: tagged typesextensions) Lionel Draghi
2000-02-05  0:00           ` scripting/extension language for Ada (was : Re: tagged types extensions) Ehud Lamm
2000-02-06  0:00             ` Lionel Draghi
2000-02-06  0:00               ` Ehud Lamm
2000-02-06  0:00               ` scripting/extension language for Ada Terry Westley
2000-02-09  0:00               ` scripting/extension language for Ada (was : Re: tagged types extensions) Robert A Duff
2000-01-31  0:00 ` tagged types extensions - language design question Mark Lundquist
2000-02-01  0:00   ` Simon Wright
2000-02-01  0:00   ` Vladimir Olensky
2000-02-01  0:00   ` Ehud Lamm
replies disabled

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