comp.lang.ada
 help / color / mirror / Atom feed
* OO implementation in Ada
@ 1996-11-02  0:00 James O'Connor
  1996-11-04  0:00 ` Norman H. Cohen
  0 siblings, 1 reply; 2+ messages in thread
From: James O'Connor @ 1996-11-02  0:00 UTC (permalink / raw)



All,
	I was discussing some OO concepts and their implementation in various 
languages with a friend and a question came up.  I have a class and 
a function that takes as a parameter an object of that class.  We
 were talking about implmenting it in various languages (Ada, Smalltalk, Java, C++).
  In most of the above languages I can subclass from the original class and send 
 objects of the subclass to the function in the same manner as objects of the parent.
  Is that true with Ada95?  Can I use objects of the subclass of a class any place 
that I can use objects of the parent class (especially, can/are clients unconcerned 
with the difference?).  I'm also curious if operations in the parent class that are 
overridden in the child class get call properly from clients that are only aware of the
 parent class.

I hope this makes sense.  I'm trying to describe an OO modelling situation that I 
would like to mirror in Ada95 specifically without providing any leading information
 on what I expect that implementation to look like because I don't know enough to
 speculate (Does it involve access types?  tagged types? 'Class tags or something else?)

Thanks

James O'Connor
oconnor@apci.net






^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: OO implementation in Ada
  1996-11-02  0:00 OO implementation in Ada James O'Connor
@ 1996-11-04  0:00 ` Norman H. Cohen
  0 siblings, 0 replies; 2+ messages in thread
From: Norman H. Cohen @ 1996-11-04  0:00 UTC (permalink / raw)



James O'Connor wrote:
> 
> All,
>         I was discussing some OO concepts and their implementation in various
> languages with a friend and a question came up.  I have a class and
> a function that takes as a parameter an object of that class.  We
>  were talking about implmenting it in various languages (Ada, Smalltalk, Java, C++).
>   In most of the above languages I can subclass from the original class and send
>  objects of the subclass to the function in the same manner as objects of the parent.
>   Is that true with Ada95?  Can I use objects of the subclass of a class any place
> that I can use objects of the parent class (especially, can/are clients unconcerned
> with the difference?).  I'm also curious if operations in the parent class that are
> overridden in the child class get call properly from clients that are only aware of the
>  parent class.
> 
> I hope this makes sense.  I'm trying to describe an OO modelling situation that I
> would like to mirror in Ada95 specifically without providing any leading information
>  on what I expect that implementation to look like because I don't know enough to
>  speculate (Does it involve access types?  tagged types? 'Class tags or something else?)

Your question is not phrased in Ada terminology, but it makes sense, and
the answer is that Ada does indeed behave as you would like it to.  

Let me translate to Ada terminology:  Instead of declaring a "class",
you declare a "tagged type" in Ada.  Instead of a "subclass" of a type
T, you declare a type "derived from" T.  When you declare a tagged type
T, you automatically also create a type T'Class 
which has one value for each value in type T and each value in any type
directly or indirectly derived from T.  Each value of type T'Class has a
"tag" indicating the type from which the value came.  Any place a value
of T'Class is allowed, the value may be one corresponding to a value of
type T or to any type directly or indirectly derived from T.  In
particular, a subprogram S declared with a formal parameter of a tagged
type T can be invoked with an actual parameter of type T'Class.  Then
the call "dispatches" to the version of S for the type indicated by the
tag.  Depending on the tag, this may be the original version of S for
type T, or it may be an overriding version of S for some type directly
or indirectly derived from T.  A part of a program can manipulate values
of type T'Class without being aware of all the places values of that
type may come from (i.e., without being aware of all the types directly
or indirectly derived from T).  Nonetheless, this part of the program
can call subprograms that dispatch to the appropriate version based on
the tag of the actual parameter.

-- 
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-11-04  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-02  0:00 OO implementation in Ada James O'Connor
1996-11-04  0:00 ` Norman H. Cohen

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