• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Large static arrays

 
Tom Bigford
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All ... I am retrofitting a java app/applet which contains a large static array
public static final byte[][] x = {{1,2,3},{4,5,6}... };
clearly this isn't a very safe array sine anyone can change the values...
Any ideas on the best way to handle a large pre-defined array like this?
TIA - Tom
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make it private and provide getters and setters, and in those methods put in whatever controls that you feel you need.
 
Tom Bigford
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cindy - I am looking for design ideas...There are several arrays of this data existing in the code - it is *ugly* - and also readily changeable. Your solution will work for the "readily changeable" part - but i would like to make this an elegant design ... At first i looked at an interface - but of course the data in an interface can only be public...(as well as static and final etc etc) - That leaves me in the same place ... This may be just too complicated to ask in this forum - but thanks for trying anyway...
Thanks again - Tom
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dunno how 'elegant' one can get with a mass of arbitrary data -- most design patterns focus on de-coupling object relationships. Data typically just comes in a file.
And you could do it that way: feed the data into the program from a file, and make the file presentation itself cleaner. For example, you could treat each array as the values of some named property. If it's structured data you could even -- dare I say it -- store it in an XML-based format.
After that, it doesn't really get any better than encapsulation.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic