From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c5ca2cbae60e9fee,start X-Google-Attributes: gid103376,public From: Ehud Lamm Subject: OO puzzle Date: 1999/12/22 Message-ID: #1/1 X-Deja-AN: 563728922 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Complaints-To: usenet@news.huji.ac.il X-Trace: news.huji.ac.il 945851984 29302 132.64.178.45 (22 Dec 1999 08:39:44 GMT) Organization: The Hebrew University of Jerusalem Mime-Version: 1.0 NNTP-Posting-Date: 22 Dec 1999 08:39:44 GMT Newsgroups: comp.lang.ada Date: 1999-12-22T08:39:44+00:00 List-Id: 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!