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,e5eb8ca5dcea2827 X-Google-Attributes: gid103376,public From: Hyman Rosen Subject: Re: Ada OO Mechanism Date: 1999/05/26 Message-ID: #1/1 X-Deja-AN: 482480035 Sender: hymie@calumny.jyacc.com References: <7i05aq$rgl$1@news.orbitworld.net> <7i17gj$1u1k@news2.newsguy.com> <7icgkg$k4q$1@nnrp1.deja.com> <3749E9EC.2842436A@aasaa.ofe.org> <7id2eo$fag@drn.newsguy.com> <3749FF7D.F17CE16A@aasaa.ofe.org> <374AC676.F7AE0772@lmco.com> <7ieuja$5v9@news1.newsguy.com> <7ifd6l$bmf@sjx-ixn1.ix.netcom.com> <7ihf6i$4hv@dfw-ixnews10.ix.netcom.com> X-Complaints-To: abuse@panix.com X-Trace: news.panix.com 927756071 17941 209.49.126.226 (26 May 1999 22:01:11 GMT) Organization: PANIX Public Access Internet and UNIX, NYC NNTP-Posting-Date: 26 May 1999 22:01:11 GMT Newsgroups: comp.lang.ada Date: 1999-05-26T22:01:11+00:00 List-Id: Richard D Riehle writes: > For example, in the same scope and visibility > type T is tagged ... > function Get(F : some-file) return T; > function Get(F : access some-file) return T; > function Get(F : some-file) return T'Class; > type B is new T with ... > function Get(F : some-file) return B; > function Get(F : access some-file) return B; Overloading by return type and having that control dispatching looks like a good example of something that you can't do in C++. So is the concept of class-wide type itself - there's no equivalent in C++ for Ada's T'Class type. From a little fooling around with your code above and gnat, and the Rationale, it looks like the compiler has to examine the code that attempts to initialize a T'Class variable and allocate the maximum space for it that that code would require. C++ doesn't do any of that - C++ coders would be using dynamic allocation and pointers or references to pass around arbitray subclasses. Interesting. > One of the original contentions was that, although the C++ model of > class <=> type <=> module > appears to be simpler on the surface, as one begins to design large > scale software, that model becomes something of a straightjacket. It > utltimately requires friend functions and other encapsulation-breaking > features (such as the new "mutable" reserved word) to get around the > restrictions imposed by such a small model of object-oriented > programming. It is a fallacy that friend functions break encapsulation. Friendship is granted explicitly by a class. These friends are part of the encapsulation. Mutable has nothing at all to do with this - mutable members of an object may be modified even when the object is declared to be 'const'. The intent is to provide a difference between logical constness and physical constness. For example, one would expect that the characters of a const string would never change, but there could be an internal reference count that needs adjustment. That count would be declared mutable. For completeness sake, class member templates *can* be used to break encapsulation. The C++ philosophy is to protect encapsulation against Murphy but not Machiavelli.