The Artima Developer Community
Sponsored Link

Class variables

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Class variables

Posted by Paul Nita on 01 Mar 1999, 1:38 PM

> As you recommonded, to enforce data-hiding, we should declare class variables as final. But what if we want to give end-user to modify the value of these variables through a plain text file? For example, we declare some file path as static string variable in a class, and then allow user to change the path in a plain text. So everything the class is loaded, it will read from the plain text file first. If the path is not defined there, it will use the default value in the class. But the client of that class won't know anything about this overriding. Do you think it violates the data-hiding thesis?

You can still define the class variable final static:
When the class is loaded, it will attempt first to initialize the static variable from
the plain text file. If the path is not defined it will initialize the
variable with the default value.
The final binding will be effective at varaible's initialization only.




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us