Skip to main content
Code Review

Return to Answer

added 362 characters in body
Source Link

Well first decide what type of object you are going to design whether its statefull or stateless. What I understood from your class purpose is to parse a parameter. The way you have designed is state full which is absolutely unnecessary and might be not thread safe (depends on usage).

Parsing is generic thing and it has no necessity to hold any state. Fine how would you use your class?

//Parsing first parameter 
ParameterParser parser1 = new ParameterParser("xx","yy");
Object parameter1 = Parser1.parse();

If I want to parse another parameter , I should create new instance which is unnecessary since its not statefull object .

ParameterParser parser2 = new ParameterParser("AA","BB");
Object parameter2 = Parser2.parse();

Instead of this you could make it as stateless object and its thread safe.

//You can also think of make it singleton or static since its stateless 
ParameterParser parser1 = new ParameterParser();
Object1 parameter1 =Parser1.parse("xx","yy");
Object1 parameter2 =Parser1.parse("AA","BB");
// You can also think of accessors method based implementation to change the behaviour at run-time. If you feel some other operations/methods are depends on your variables passed in then consider this one... This is not thread safe by nature but you can make it as thread safe. 
ParameterParser parser1 = new ParameterParser();
parser1.setXXX("xxx");

Cheers!

Well first decide what type of object you are going to design whether its statefull or stateless. What I understood from your class purpose is to parse a parameter. The way you have designed is state full which is absolutely unnecessary and might be not thread safe (depends on usage).

Parsing is generic thing and it has no necessity to hold any state. Fine how would you use your class?

//Parsing first parameter 
ParameterParser parser1 = new ParameterParser("xx","yy");
Object parameter1 = Parser1.parse();

If I want to parse another parameter , I should create new instance which is unnecessary since its not statefull object .

ParameterParser parser2 = new ParameterParser("AA","BB");
Object parameter2 = Parser2.parse();

Instead of this you could make it as stateless object and its thread safe.

//You can also think of make it singleton or static since its stateless 
ParameterParser parser1 = new ParameterParser();
Object1 parameter1 =Parser1.parse("xx","yy");
Object1 parameter2 =Parser1.parse("AA","BB");

Cheers!

Well first decide what type of object you are going to design whether its statefull or stateless. What I understood from your class purpose is to parse a parameter. The way you have designed is state full which is absolutely unnecessary and might be not thread safe (depends on usage).

Parsing is generic thing and it has no necessity to hold any state. Fine how would you use your class?

//Parsing first parameter 
ParameterParser parser1 = new ParameterParser("xx","yy");
Object parameter1 = Parser1.parse();

If I want to parse another parameter , I should create new instance which is unnecessary since its not statefull object .

ParameterParser parser2 = new ParameterParser("AA","BB");
Object parameter2 = Parser2.parse();

Instead of this you could make it as stateless object and its thread safe.

//You can also think of make it singleton or static since its stateless 
ParameterParser parser1 = new ParameterParser();
Object1 parameter1 =Parser1.parse("xx","yy");
Object1 parameter2 =Parser1.parse("AA","BB");
// You can also think of accessors method based implementation to change the behaviour at run-time. If you feel some other operations/methods are depends on your variables passed in then consider this one... This is not thread safe by nature but you can make it as thread safe. 
ParameterParser parser1 = new ParameterParser();
parser1.setXXX("xxx");
Source Link

Well first decide what type of object you are going to design whether its statefull or stateless. What I understood from your class purpose is to parse a parameter. The way you have designed is state full which is absolutely unnecessary and might be not thread safe (depends on usage).

Parsing is generic thing and it has no necessity to hold any state. Fine how would you use your class?

//Parsing first parameter 
ParameterParser parser1 = new ParameterParser("xx","yy");
Object parameter1 = Parser1.parse();

If I want to parse another parameter , I should create new instance which is unnecessary since its not statefull object .

ParameterParser parser2 = new ParameterParser("AA","BB");
Object parameter2 = Parser2.parse();

Instead of this you could make it as stateless object and its thread safe.

//You can also think of make it singleton or static since its stateless 
ParameterParser parser1 = new ParameterParser();
Object1 parameter1 =Parser1.parse("xx","yy");
Object1 parameter2 =Parser1.parse("AA","BB");

Cheers!

lang-cs

AltStyle によって変換されたページ (->オリジナル) /