Re: How do you implement global data?



Knute Johnson wrote:
I have some data that I need to have accessible to multiple classes. The data is initialized from the constructor of one class by reading a file. That same class has an editor that can modify that data. Currently I'm just creating the variables as static in the one class. Findbugs complains that this is "tricky (which it is) and bad practice". How would you setup shared data under these conditions?

I'm not sure I understand the question completely.

You're saying you read some data from a file and stuff it in a static variable?

class Editor {
static String myData;

public Editor( IOStreamReader file ) {
// read data into myData from file...
}
}

Yes, this is pretty evil. If you need direct access to the data, you should at least go through a getter and a setter. JTextArea has, iirc, a getText and a setText. So if a second class needs to modify myData, it uses the getter, makes changes, then invokes the setter. However in any case I'd ditch the static modifier. It's not needed and will probably produce some really unexpected behavior eventually.

If you're asking something different, I'm not sure what it is. More info?
.



Relevant Pages

  • A simple question
    ... I have use the Page Viewer Web Part but i want when i do modify the page ... The Content Editor its fit me but, i have this problem, i want for the quick ... editorwebpart and in the default page, i have a PageViewer Web part. ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: WTL CCombobox with CBS_DROPDOWNLIST style
    ... "Properties/Behavior" in resource editor... ... At the moment all of my controls are initialized with DDX_CONTROL_HANDLE ... I would like to modify the Combobox control from default DROPDOWN style ...
    (microsoft.public.vc.atl)
  • Re: which queries use table X?
    ... >I have to modify how tables X, Y and Z are used throughout this app. ... >use FIND in the VB Editor to search all Forms and Modules in the whole ... There are several tools that have been written by third parties to do ...
    (microsoft.public.access.gettingstarted)
  • Re: Database Editor Fields
    ... To find the best Newsgroup for FrontPage support see: ... and have created a Database Editor to modify existing | records in an access db. ... The edit page of the editor uses all free-form text | fields for modifying existing data, even if it was submitted via drop down | box forms. ... | Is there a way to use drop down boxes in the db editor as you would in a | standard form to modify data? ...
    (microsoft.public.frontpage.client)
  • Re: Telegraph Tuesday 22nd SPOILER
    ... border returning = leni ... Odd! ... Perhaps the setter had something like 'head to tail' and the editor ...
    (rec.puzzles.crosswords)