comp.lang.ada
 help / color / mirror / Atom feed
From: zmhasan@watdragon.waterloo.edu (Ziaul Masum Hasan)
Subject: Re: Integrating concurrent & O-O programming
Date: 23 Nov 89 02:52:43 GMT	[thread overview]
Message-ID: <18501@watdragon.waterloo.edu> (raw)
In-Reply-To: 1667@osc.COM

In article <1667@osc.COM> tma@osc.UUCP (Tim Atkins) writes:
>In article <7062@hubcap.clemson.edu> wtwolfe@hubcap.clemson.edu (Bill Wolfe) writes:
>> ...consider the interference that occurs between class inheritance 
>> and encapsulation when subclasses are allowed to access freely the 
>> instance variables of the parent class [Sny86].  In this case we may 
>> say that support for inheritance diminishes the degree of encapsulation
>> that was achieved without inheritance...
>
>
>I have heard this before and, frankly, I don't get it.  The subclass 
>has inherited data structure definition from the parent class.  Therefore
>its instances will contain instances of the parent data structure.  This
>is totally local to the object!  Only the definition was inherited.  Why
>is this a bad thing?  Why does it break encapsulation?  I understood the
>encapsulation wrt data provided by OO techniques to simply state that instance
>data should not be accessed directly but only through a method defined on
>the class.  Therefore, inheritance does not seem to break encapsulation.
>
>I would appreciate it if someone could set me straight here.
>
>- Tim



Aren't you confusing runtime behavior with compilation time?

Encapsulation hides representation.
Accessing instance variables means you can directly use or refer to that 
variable in any method that you define in the subclass (S) of a class (C).
In other words, the scope of this variable defined in C spans up to the 
subclass. Of course, this violates encapsulation (or information hiding).
If the representation of the instance variable is changed in C (say, from
array to linked list), all the methods in all the subclasses down the class
hierarchy that used that variable directly have to be rewritten and recompiled.
Had we used method to access (refer) that variable, modification in one class
was sufficient.
Languages vary in defining what to inherit.
In smalltalk subclasses inherit both instance variables and methods. Any method 
can directly use any inherited instance variable. But any other class that is 
not a suclass of a class C, but simply uses C by creating an instance of it, can
access variables of C only through methods.
In some other languages a class can access instance vriables of any other
class only through methods.
C++ has a flexible mechanism in defining what to inherit i.e., public, private, friend constructs.

Masum Hasan

  parent reply	other threads:[~1989-11-23  2:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1989-11-15 19:30 Integrating concurrent & O-O programming Bill Wolfe
1989-11-21  4:09 ` Tim Atkins
1989-11-22 22:08   ` 3929
1989-11-22 22:37   ` Dan Weinreb
1989-11-23  2:52   ` Ziaul Masum Hasan [this message]
1989-11-23  9:46   ` Re^2: " NIERSTRASZ Oscar
1989-11-23 16:18     ` BJORNERSTEDT Anders
1989-11-26 14:04       ` Markku Sakkinen
1989-11-23 14:56   ` BJORNERSTEDT Anders
replies disabled

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