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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2ea02452876a15e1 X-Google-Attributes: gid103376,public From: donh@syd.csa.com.au (Don Harrison) Subject: Re: Choice of OO primitives in Ada95 Date: 1996/02/21 Message-ID: #1/1 X-Deja-AN: 140375011 sender: news@assip.csasyd.oz references: <4gc2pu$6qj@ux1.lmu.edu> organization: CSC Australia reply-to: donh@syd.csa.com.au newsgroups: comp.lang.ada Date: 1996-02-21T00:00:00+00:00 List-Id: Ray Toal wrote: :donh@syd.csa.com.au (Don Harrison) wrote: : :>1) Why should you have to specify that a type is 'tagged'? Can't the compiler work :>that out for itself? eg. by seeing whether the type is extended elsewhere. The :>developer is forced to worry about what should be an implementation issue. : :Requiring 'tagged' is a GOOD THING! Inheritance weakens encapsulation. Not sure what you mean by this. Inheritance is no weaker or stronger in languages (such as Eiffel) which map classes onto the encapsulation mechanism. :The default case (no tagged) is that you design a type, and you :provide all and only those operations that work on the type and you :don't make any details available to anyone else - in short you :fully control the type. Now if your intent is to ALLOW derivation :then you must mark it tagged. This alerts the reader that this :type may be derived from. Imagine a language in which you could :inherit from any type you wanted to! :-) Yes, it's called Eiffel and it's great having such flexibility! :-). One aspect of that flexibility is that, if, one sunny day, you decide you need to extend a type you go right in and do it and don't have to touch the original. In Ada, you have to go back and redefine the type to make it tagged. The impact of this may be limited to that - don't know, haven't thought about it - but you shouldn't have to redefine something to reuse it. : Whether or not a type :should be tagged is a DESIGN decision; I totally disagree that it :should be an implementation decision. By the way a compiler can not :in general determine if the "type is extended elsewhere" since in :Ada extensions can appear in other compilation units. I can't think offhand of a suitable way of dealing with this but that isn't to say it's impossible. :>2) Similarly, why should the developer have to specify that an operation dispatches :>(classwide operations)? Presumably, you're aiming for quicker execution, but :>compilers could perform a certain degree of optimisation eg. If it knows the type :>is not extended anywhere, there is no need to dispatch. There would also be :>situations where the specific variant of an inherited type is known eg. following :>an explicit assignment from an entity of that type. : :The reason you need to specify whether or not an operation dispatches :is that you can write code like : : procedure P (X: T) is begin R(X); end P; : procedure Q (X: T'Class) is begin R(X); end Q; : :which behave differently. You don't have to do it that way. You can use (for example) a synonym construct like procedure P, Q (X: T) is begin R(X); end P, Q; and redefine Q for extensions of X. : :Ray Toal : : Don.