Re: Can use of singletons denote poor project design?



Daniel Parker wrote:

Well, in that case, you may as well use this one.

class Singleton {
static Singleton instance = new Singleton();

Singleton getInstance() {return instance;}

int flag;
int input;
int output;

void setFlag(int flag) {this.flag = flag;}
int getFlag() {return flag;}
void setInput(int input) {this.input = input;}
int getInput() {return input;}
void setOutput(int output) {this.output = output;}
int getOutput() {return output;}
}

void main(String[] args) {
Singleton.getInstance().setFlag(7);
Singleton..getInstance().setInput(3);

doSomething();
}

void doSomething() {
if (Singleton.getInstance().getFlag() == 2) {
int x = Singleton.getInstance().getInput();
Singleton.getInstance().setOutput(x+20);
}else if (Singleton.getInstance().getFlag() == 7) {
int x = Singleton.getInstance().getInput();
Singleton.getInstance().setOutput(x+29);
}
}

Sigh. This brings back memories of "Bob". Bob didn't like to pass
parameters. Bob liked global flags that changed what functions did. Bob
didn't like "else". Bob wrote in C and assembly on PC's with DOS
extenders, and when you'd call one of his functions to say, calculate a
bond price, the printer would print some hex characters, or things of that
sort. Everyday I would come in and remove a little bit of Bob.

I'm sorry, Daniel. I didn't know.

I hope you are recovering.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!


.



Relevant Pages