comp.lang.ada
 help / color / mirror / Atom feed
* Ada OO
@ 1996-11-25  0:00 Graham Hughes
  1996-11-25  0:00 ` Robert A Duff
  0 siblings, 1 reply; 8+ messages in thread
From: Graham Hughes @ 1996-11-25  0:00 UTC (permalink / raw)



-----BEGIN PGP SIGNED MESSAGE-----

I apologize if this has been glossed over before, but I didn't notice
anything immediately through the back articles.

The tutorials at http://www.adahome.org/ seem to gloss over the way Ada
OO is handled; possibly this is because they believe it to be so simple
that their explanation suffices.  However, I'm coming from C++, where OO
is quite complicated, and I'm not sure I've quite got a handle on it
yet.

- From what I've seen, Ada OO is very similar to CLOS; both use the

    Object_Method(Object, Args);

syntax instead of the C++-style

    Object.Object_Method(Args);

where Object is a tagged record.

Given this, how are C++-style virtual methods defined?  The stuff I've
looked at implied that all subprograms defined in the package spec are
virtual, and pure virtual methods are achieved by (appending?
prepending?) abstract to the definition.

With CLOS, all defmethod (or is it defgeneric? been a while) methods are
effectively virtual, and pure virtual methods are just a defgeneric (?)
with no body definitions.  Is this the way Ada OO works?

Finally, re: the abstract; is it needed in the package body, or can it
be ommitted?

Thanks for any help.
- -- 
    Graham Hughes (graham.hughes@resnet.ucsb.edu)
alt.PGPlike-key."graham@A-abe.resnet.ucsb.edu".finger.look.examine
alt.homelike-page."http://A-abe.resnet.ucsb.edu/~graham/".search.browse.view
alt.silliness."http://www.astro.su.se/~robert/aanvvv.html".look.go.laugh

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBMpjr6iqNPSINiVE5AQFw3AP/UMeHylSkz0Y++9uvJsbPSbTwmQH4Y3vF
eN5AiLyTLtXFyk4TQqs7cVjhhd8yDfv1mhtU5eWA/NIAcHEhbcdggz4qr8/6j1zR
ZcAE65nRY9s6dbsPXRYzZJiZYkbEygS3SaHuZxm1NAfrOoSE1zsgTlf6cAsmsfAC
agpg1XlnA58=
=d/vL
-----END PGP SIGNATURE-----




^ permalink raw reply	[flat|nested] 8+ messages in thread
* Ada OO
@ 2002-10-08  2:17 Rick Duley
  2002-10-08  9:28 ` John McCabe
  2002-10-08  9:54 ` John McCabe
  0 siblings, 2 replies; 8+ messages in thread
From: Rick Duley @ 2002-10-08  2:17 UTC (permalink / raw)


Hi all

I believe that I am the last surviving academic Ada programmer in Perth, 
Western Australia and I am in need of some help.  I am having problems 
coming to terms with the rationale behind Object Oriented programming in Ada 
and there is no-one I know in Perth to talk to.  I'm hoping you folk won't 
mind giving me a hand.

Perhaps I had better start by explaining my (mis-) understanding of the 
general principle of inheritance.

Suppose I have defined an object Pen_Class to have the form:

+-------------------------------------------+
| Pen                                       |
+-------------------------------------------+
| X     : Integer;                          |
| Y     : Integer;                          |
| Color : Color_Type;                       |
+-------------------------------------------+
| procedure Move_To(This : in out Pen;      |
|                   X    : in     Natural;  |
|                   Y    : in     Natural); |
| -- move the pen to the specified location |
| --  without drawing                       |
|                                           |
| procedure Draw_To(This : in out Pen;      |
|                   X    : in     Natural;  |
|                   Y    : in     Natural); |
| -- draw a line from the current location  |
| --  to (X,Y) using the pen's              |
| --  current color.  the pen's location    |
| --  moves to (X,Y)                        |
|                                           |
| function New_Pen(X     : Natural;         |
|                  Y     : Natural;         |
|                  Color : Color_Type)      |
| return Pen_Access;                        |
| -- returns access to an initialised Pen   |
+-------------------------------------------+

This object should be initialised by New_Pen and all the functionality it 
should need should be supplied by the other two methods.  Of course, if you 
want to change Pen Colour in midstream you would have to provide the 
functionality to do so but let's keep this simple so I can get a handle on 
it ;)

Extension of this class to Thick_Pen_Class should, according to me, result 
in a class having the form:

+-------------------------------------------+
| Thick_Pen                                 |
+-------------------------------------------+
| X         : Integer;                      |
| Y         : Integer;                      |
| Color     : Color_Type;                   |
| Thickness : Positive;                     |
+-------------------------------------------+
| --=== inherited from Pen_Class ===--      |
| procedure Move_To(This : in out Pen;      |
|                   X    : in     Natural;  |
|                   Y    : in     Natural); |
| -- move the pen to the specified location |
| --  without drawing                       |
|                                           |
| procedure Draw_To(This : in out Pen;      |
|                   X    : in     Natural;  |
|                   Y    : in     Natural); |
| -- draw a line from the current location  |
| --  to (X,Y) using the pen's              |
| --  current color.  the pen's location    |
| --  moves to (X,Y)                        |
|                                           |
| function New_Pen(X     : Natural;         |
|                  Y     : Natural;         |
|                  Color : Color_Type)      |
| return Pen_Access;                        |
| -- returns access to an initialised Pen   |
|                                           |
| --=== new in Thick_Pen_Class ===--        |
| procedure Move_To(This : in out Thick_Pen;|
|                   X    : in     Natural;  |
|                   Y    : in     Natural); |
| -- move the pen to the specified location |
| --  without drawing                       |
|                                           |
| procedure Draw_To(This : in out Thick_Pen;|
|                   X    : in Natural;      |
|                   Y    : in Natural);     |
| -- draw a line from the current location  |
| --  to (X,Y) using the pen's              |
| -- current color.  the pen's location     |
| --  moves to (X,Y).  The                  |
| -- vertical thickness of the pen is given |
| --  by Thickness.                         |
|                                           |
| function New_Thick_Pen                    |
|    (X         : Natural;                  |
|     Y         : Natural;                  |
|     Color     : Color_Type;               |
|     Thickness : in Positive)              |
| return Thick_Pen_Access;                  |
| -- returns access to initialised Thick_Pen|
|-------------------------------------------+

I would expect all the class attributes, the data variables, to be accessed 
by the methods of the derived class with the overloading providing the 
polymorphism.  My problems start when this doesn't happen.

1.   All the texts I can find which deal in any degree at all with OO in Ada 
teach that the tagged record in an object declaration should be 'private'.  
When you follow this line, a derived class does not have direct access to 
the object attributes of the base class, i.e. _there_is_no_inheritace_.

2.   To provide the derived class with access to the object attributes of 
the base class I have to create user-defined methods in the base class.  
This has two effects:
     a) the object attributes of the base class are now effectively public, 
i.e. accessible (through the user-defined methods) to any client module 
through 'with' and 'use' -  which effectively negates the act of making them 
private in the first place;
     b) having to provide accessibility in this manner emphasises the fact 
that inheritance did not occur.

3.   If the tagged record in the base class is left public and the derived 
class is in a child package of the package defining the base class, then the 
base class attributes are accessible to the derived class.  So far so good 
:)  However, if in a program 'use'ing the child package of 'Thick_Pen' (and 
not mentioning the base package of 'Pen') I make a call to the routine 
'Draw' with an actual parameter of the type 'Pen' I get a compiler error 
message to the effect that 'Draw' is not visible.  In other words, Thick_Pen 
has not inherited the operation Draw for 'Pen'  Again, 
_there_is_no_inheritace_.

4.  Further along that line, Thick_Pen does not inherit the type Pen so I 
cannot declare a Pen (or Pen_Access) unless I 'with' and 'use' the package 
in which Pen is declared.  This means that making the package in which 
Thick_Pen is declared a child of the package in which Pen is declared 
totally useless.  _There_is_no_inheritance_!

I have to say that this is the first time in pretty near a decade I have 
been writing in and teaching with Ada that Ada hasn't come up with the 
goods.  Do I labour under some serious misunderstanding, do I have something 
terribly wrong?

5.   One final thing (for this time anyway ;), why is it that that Ada does 
not use the intuitive 'object.method' syntax for making calls to and object. 
   This would mean that (in the case described in section 3) the call would 
read

	Pen.Draw(To_X => n, To_Y => n);

and with inheritance this would be accessible through the child package 
declaring Thick_Pen.  While I'm okay with using the existing syntax, I feel 
the 'object.method' syntax is more intuitive and in line with OO thinking.  
If there are people working on Ada0x then maybe we shoo\uld be putting this 
forward for consideration.


So, you see, I'm all at sea.  Can someone help me out?
Thanks



-------------------------------------------------
Rick Duley
23/209 Walcott St
North Perth, Western Australia 6006
mob: +61 040 910 6049
                                /-_|\
                               /     \
                         perth *_.-._/
                                    v
Experience is the worst of teachers
       It gives you the exam
                before it gives you the lecture


_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




^ permalink raw reply	[flat|nested] 8+ messages in thread
[parent not found: <F44Lnlyg35sQtgTIFpr0000279d@hotmail.com>]

end of thread, other threads:[~2002-10-08 18:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-25  0:00 Ada OO Graham Hughes
1996-11-25  0:00 ` Robert A Duff
1996-11-25  0:00   ` Graham Hughes
  -- strict thread matches above, loose matches on Subject: below --
2002-10-08  2:17 Rick Duley
2002-10-08  9:28 ` John McCabe
2002-10-08  9:54 ` John McCabe
2002-10-08 18:37   ` tmoran
     [not found] <F44Lnlyg35sQtgTIFpr0000279d@hotmail.com>
2002-10-08  3:01 ` David C. Hoos, Sr.

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