comp.lang.ada
 help / color / mirror / Atom feed
From: magnus@lglsun.epfl.ch (Magnus Kempe)
Subject: Encapsulation in Ada vs. C++ (Was Re: Ichibah [sic] ...)
Date: 11 Mar 93 08:04:10 GMT
Date: 1993-03-11T08:04:10+00:00	[thread overview]
Message-ID: <1993Mar11.082214@lglsun.epfl.ch> (raw)
In-Reply-To: 1993Mar9.181231.27197@intellistor.com

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



  reply	other threads:[~1993-03-11  8:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-03-07 19:15 Ichibah flames, and flames out over, Ada 9X John Goodsen
1993-03-08  0:45 ` David Emery
1993-03-08 15:36 ` Tucker Taft
1993-03-08 16:28   ` Michael Feldman
1993-03-08 22:15     ` Gregory Aharonian
1993-03-09 14:20       ` Tucker Taft
1993-03-09 14:55         ` C. Michael Holloway
1993-03-10 14:51         ` Gregory Aharonian
1993-03-09 17:12       ` Harry Koehnemann
1993-03-09 20:54         ` Michael Feldman
1993-03-09 20:14       ` Larry M. Jordan
1993-03-09 17:49     ` Harry Koehnemann
1993-03-09 21:01       ` Michael Feldman
1993-03-09 18:12   ` Tom Wicklund
1993-03-11  8:04     ` Magnus Kempe [this message]
1993-03-16  6:34       ` Encapsulation in Ada vs. C++ (Was Re: Ichibah [sic] ...) Dag Bruck
1993-03-16  7:51         ` Magnus Kempe
1993-03-16  9:51           ` Dag Bruck
1993-03-09 18:53   ` Ichibah flames, and flames out over, Ada 9X Larry M. Jordan
1993-03-09 20:24     ` David Weller
1993-03-09 21:03       ` Michael Feldman
1993-03-12 14:49         ` Tucker Taft
1993-03-12 23:54           ` Michael Feldman
1993-03-16 17:34   ` Robert Firth
  -- strict thread matches above, loose matches on Subject: below --
1993-03-16 22:37 Encapsulation in Ada vs. C++ (Was Re: Ichibah [sic] ...) John Goodsen
replies disabled

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