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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7251fa99aab97e06 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1993-03-11 01:01:48 PST Path: sparky!uunet!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!ira.uka.de!scsing.switch.ch!sicsun!disuns2.epfl.ch!lglsun!magnus From: magnus@lglsun.epfl.ch (Magnus Kempe) Newsgroups: comp.lang.ada Subject: Encapsulation in Ada vs. C++ (Was Re: Ichibah [sic] ...) Message-ID: <1993Mar11.082214@lglsun.epfl.ch> Date: 11 Mar 93 08:04:10 GMT References: <1993Mar7.191557.5547@evb.com> <1993Mar8.153639.3603@inmet.camb.inmet.com> <1993Mar9.181231.27197@intellistor.com> Organization: Ecole Polytechnique Federale de Lausanne NNTP-Posting-Host: lglsun4.epfl.ch Date: 1993-03-11T08:04:10+00:00 List-Id: Taft showed how a package allows one to encapsulate _several_ types and their operations, providing such natural and efficient notations as "A := 2 + 3 * i;" ("A" is of type Complex and "i" is of type Imaginary; "+" and "*" are the operations). The crux of Taft's example is that Ada allows one to declare _several_ types _together_ and thus be able to easily provide an efficient subprogram operating on _several_ objects of _different_ types. All this can be achieved within a package with the safety provided by private types (since no one else is allowed to proclaim itself so "friendly" as to see the private parts of your package...). To achieve this, operators would have to be "friends" in C++, because of its equation "module = class"; however, the problem with such an approach is that _anyone_ can then claim to be a "friend", and therefore _anyone_ can break the abstraction of the class. C++ "friends" break the encapsulation and its equation becomes an approximation: "a class with friends is almost a module". wicklund@intellistor.com (Tom Wicklund) answered Taft with an irrelevant example: : : I suggest you look at the GNU g++ library implementation of complex, : which I summarize below. Note that there are NO friend functions. Of course, there are no friends in your C++ code (not repeated here), since the C++ class you included does _not_ propose _two_ types and operations working on objects of both types. (BTW, I'd rather see a discussion of principles with approriate examples; pouring hundreds of lines of C++ code in comp.lang.ada is uninteresting. Thank you.) To summarize, the crucial concepts involved are the following: we want a natural notation to declare several types and associated, efficient subprograms operating on several parameters of different types, and we want all this while preserving the abstraction in its encapsulation and type safety. Ada satisfies such software engineering requirements, and Ada 9X will soon provide still more programming power to satisfy still more software engineering requirements. (How great!) -- Magnus Kempe "No nation was ever drunk when wine was cheap." magnus@lglsun.epfl.ch -- Thomas Jefferson