comp.lang.ada
 help / color / mirror / Atom feed
* OO puzzle
@ 1999-12-22  0:00 Ehud Lamm
  1999-12-22  0:00 ` Tucker Taft
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Ehud Lamm @ 1999-12-22  0:00 UTC (permalink / raw)


The recent threads about languages for OO development, made me think the
following may interest readers here.
 


I am now quouting a bit from the book "Eiffel the language", so I am
describing Eiffel and not Ada, consider how these language differ, and try
to think why. This will lead to an answer to the design question ahead:

" (P1) A Class may override the export policies of its parents; it may for
example make secret its version of a feature which the parent exported"
Can you do this in Ada? How? What does it mean to the "IS-A" meaning of
ihnheritance?

" (P2) The routine redifinition may replace the type of a formal argument
by a type conforming to the original (covariant argument policy)"
This meains that when you inherit (think of comparable above) you can
replace the argument with any type that is inherited from it. But for this
to make sense, we are talking of more than one type - because you are
doing this change, as part of inheriting the routine. 
Basically this means that is you have a function 
   Stack.Push(Node)

and you inherit to create Stack_Array than you can also change the
argument Node to something that inherits from Node:
  Stack_Array.Push(Node_Array)

Can you do this in Ada (think of what we saw above about comparable)? So
what is the Ada solution in this case? Can you do this in Java (is Java
"covariant")? 

---------------------------------------------------------------------

Now how does this affect design?
This example is again from the Eiffel book.

1. Truck_Driver IS-A Driver (one hierrachy)

2. Motor_Vehicle (and all its kids)  support the operation
register_Driver(d:driver) the paramter is of type driver above.

   Car IS-A Motor_Vechicle 
   Truck IS-A Motor_Vehicle
     Truck wants to override register_driver(d:truck_driver) becuase only
truck drivers should be allowed here.

Can yuo do this in Ada? Try, and show your error messages! How can you do
something to achive the same result, in Ada? 

I qoute:
"Examples of this kind, with two prallel inheritance hierarchies, are a
constant occurrence in the development of systems and their class
hierarchies. Many appear in the Data Strcuture Library" (the Eiffel
library of trees etc.) "For example, to describe a doubly linked list,
TWO_WAY_LIST inherits from LINKED_LIST; to describe two-way chained linked
cells, BI_LINAKBLE inherits from LINKABLE. The list classes have
procedures for manipulating list celss, such as put_linkable_left, which
quite naturally take arguments of type LINKABLE imn LINKED_LIST and
BI_LINKABLE in TWO_WAY_LIST"

A bit complicated hierrachies, but this is simple comapred to what you may
find in real life applications!

Can you do this in Ada? How? 


Well this is quite a lot, and not easy to understand, but I hope you will
find it interesting. If you have questions/ideas I'd be happy to hear. 
You may find this page interesting:
http://www.eiffel.com/doc/manuals/technology/typing/intro.html


So what do you guys suggest as the proper Ada way in these cases?

Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== My home on the web 
Check it out and subscribe to the E-List- for interesting essays and more!






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

end of thread, other threads:[~2000-01-03  0:00 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-22  0:00 OO puzzle Ehud Lamm
1999-12-22  0:00 ` Tucker Taft
1999-12-23  0:00   ` Ehud Lamm
1999-12-23  0:00     ` Robert Dewar
1999-12-23  0:00       ` Ehud Lamm
1999-12-24  0:00         ` swhalen
1999-12-25  0:00           ` Ehud Lamm
1999-12-25  0:00         ` Ehud Lamm
1999-12-29  0:00     ` Brian Rogoff
1999-12-30  0:00       ` Jeffrey L Straszheim
1999-12-31  0:00         ` Brian Rogoff
1999-12-31  0:00           ` Jeffrey L Straszheim
2000-01-02  0:00             ` Brian Rogoff
2000-01-03  0:00             ` Matthew Heaney
1999-12-22  0:00 ` Ted Dennison
1999-12-23  0:00   ` Ehud Lamm
1999-12-23  0:00     ` Ted Dennison
1999-12-25  0:00       ` Ehud Lamm
1999-12-23  0:00     ` Robert A Duff
1999-12-25  0:00       ` Ehud Lamm
1999-12-22  0:00 ` Jeff Carter

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