How to block/bulk reset static variables using Java 7 -


i parsing text file looking syntax matches. complete task, created variable class static variables in it. parse file , assign parsed information variable class static elements.

variable.name = "the parsed information";  

then created baseline class check , compare against variable elements check if condition met.

for example

if (baseline.x.equal(variable.x) // whatever. 

variable class:

public class variable {     static string name;      static string userid;     static integer age } 

baseline class:

public class baseline {         static string name;          static string userid;         static integer age     } 

utilizing javafx move between scenes load file, parse it, assign parsed variable compare baseline class. far, works expected until hit button go original scene load new file. now, issue having how can reset variable inside variable class in bulk instead of doing 1 one inside controller initialize statement? want ensure don't capture variable older file parsed before hit button. correct way of completing task?

i able looking when reset variables inside initialize controller, seems lengthy process oop have on 100 variables (int/sets/strings...) reset.

here did reset static variables inside controller initialize section.

 @override         public void initialize(url url, resourcebundle rb) {              variable.name = null;             variable.setname.clear();             variable.age = null;              

i able looking when reset variables inside initialize controller, seems lengthy process oop have on 100 variables (int/sets/strings...) reset.

if have hundreds of static variables, not doing oop properly. in proper oo design, application's state should held in instance variables, , accessed via instance variables. static variables should kept absolute minimum. (you can eliminate them entirely, if can use dependency injection (di) framework ...)

the bad news there no >>good<< way reset large number of static variables. there couple of >>bad<< ways; e.g. reflection, , messing around classloaders ... replacing 1 problem (clunky code) worse 1 (complex, fragile code). imo.

but news fix design / implementation oo, won't have nasty problem of resetting variables. , whole bunch of other things easier ... writing unit tests.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -