Newsgroups: comp.lang.java,comp.object,comp.object.logic
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!news.mathworks.com!news.kei.com!nntp.coast.net!swidir.switch.ch!CERN.ch!dxnews.cern.ch!kruse
From: kruse@cms2.cern.ch (Andres Kruse)
Subject: Re: Java public instance variables harmful?
In-Reply-To: tjb839@zacatecas.optimum.com's message of 8 Mar 1996 23:18:56 GMT
X-Nntp-Posting-Host: cms2.cern.ch
Message-ID: <KRUSE.96Mar10155506@cms2.cern.ch>
Sender: news@news.cern.ch (USENET News System)
Organization: CERN European Lab for Particle Physics
References: <KRUSE.96Mar6131047@cms6.cern.ch> <4hkhnv$5ne@decaxp.harvard.edu>
	<4hqf90$o18@jalisco.optimum.net>
Date: Sun, 10 Mar 1996 14:55:06 GMT
Lines: 55
Xref: glinda.oz.cs.cmu.edu comp.lang.java:30303 comp.object:45598 comp.object.logic:732

In article <4hqf90$o18@jalisco.optimum.net> tjb839@zacatecas.optimum.com (Tim Boemker) writes:

   In article <4hkhnv$5ne@decaxp.harvard.edu>
   robison@mito.harvard.edu (Keith Robison) writes:

   > If you have no public instance variables and use methods to get & 
   > set values, it gives much more control & future flexibility.  
   > It's too bad the AWT designers have already set such a poor example
   > with Point, Dimension, Rectangle, etc.

   It seems to me that there is a legitimate use for public instance
   variables: when part of the class's public interface includes methods
   to set and get a quantity, and when that quantity can logically contain
   any value regardless of the rest of the object's state, then that
   quantity can be implemented as a public instance variable.

   Tim Boemker
   Optimum Group

Fine, as long as it is possible to change the implementation
of the public instance variable into a method (and back) at any point
in the lifetime of the object, without breaking the code.
   The way the language specifies it now this is not an option,
so once an object has revealed this information about it's 
implementation detail there is no way you can change that.
   If you consider a public instance variable being part of the
objects interface you have to agree that noone except the
object itself has to know how the instance variable is
implemented and if it is at all a true variable. That's what's
meant by "information hiding", no?

There are many reasons for wanting to change it into a method,
one just came to my mind: Suppose you need to know when the instance
variable of a given object changes. You could then put a method 
in your code and throw an exception whenever anyone changes
the instance variable.

Another one I mentioned in an earlier post: Suppose you find
out for your graphics applications that it's pretty stupid to
use a coordinate system x,y,z in your objects because your
objects are mainly used in spherical coordinates r,theta,phi.
It would now be great if you could just have those new 
coordinates as the instance variables and the old coordinates
as methods.. It would certainly speed up the application
if it wasn't necessary to convert everyting into spherical
coordinates, right? But with the current Java design you
can't change it.

    Andres


-- 
-------------------------------------------------------
Andres Kruse, kruse@cern.ch | CERN Geneva, ECP division
-------------------------------------------------------
