Newsgroups: comp.lang.java,comp.object,comp.object.logic
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!EU.net!CERN.ch!dxnews.cern.ch!kruse
From: kruse@suncms.cern.ch (Andres Kruse)
Subject: Re: Java public instance variables harmful?
In-Reply-To: plb@idm.com's message of Sun, 10 Mar 1996 16:35:12 GMT
X-Nntp-Posting-Host: suncms.cern.ch
Message-ID: <KRUSE.96Mar14221007@suncms.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>
	<Do28qp.IqL@idm.com>
Date: Thu, 14 Mar 1996 21:10:06 GMT
Lines: 40
Xref: glinda.oz.cs.cmu.edu comp.lang.java:31562 comp.object:45901 comp.object.logic:753

In article <Do28qp.IqL@idm.com> plb@idm.com (Peris Brodsky) writes:

   Keith Robison (robison@mito.harvard.edu) wrote:
   > Andres Kruse (kruse@cms6.cern.ch) wrote:

[snip]

   > :   The fact that instance variables can be made public seems very
   > : dangerous and IMHO it's clearly against the idea of encapsulation.
   > :   But, that wouldn't be such a big problem if there was a way to
   > : sort of fake a public instance variable through an access method.

   > IMHO it is rather a bad idea to add a possibly complicated idea
   > to the language to allow folks to cover their bad OO design.
   >   
   > 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 DOES set a bad example, esp. considering the OOD acumen of
   the average Java hacker out there, but its justified for such
   primitive classes as these.  When will Point.x and Point.y ever
   disappear as integral fields?  I'm willing to risk it in exchange for
   a faster graphics-intensive application.

But if you worked on the same project with a large group of people
who you might never see once in your lifetime, wouldn't you want
the design of the system forbid "bad behaviour"? And if that's not
possible wouldn't you like the system to behave nicely when you
find out that somebody screwed up badly in the design of a class?

Maybe the Java designers could at least have a compiler flag that
enables checking for public instance variables?

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