shakesmove
BAN USER- -1of 1 vote
Answerspublic abstract class Session{ private Object objectId; //... other fields public abstract void processRequest(InputStream in); } public XmlSession implements Session{ public void processRequest(InputStream in){ System.out.println("XML RESPONSE"); // DO STUFF TO XML RESPONSE } } public JSonSession implements Session{ public void processRequest(InputStream in){ System.out.println("JSON RESPONSE"); // DO STUFF TO JSON RESPONSE } } public static void main(String args[]){ Session session = new XmlSession(); session.processRequest(); Session session = ....; session.processRequest(); }
I would like to change my design in a way that I will not lose the Session object and I don't change the client code that instanciate the XmlSession.
- shakesmove in Germany for Devoper
Could it be useful the prototype pattern? If yes why?| Report Duplicate | Flag | PURGE
Software Engineer / Developer Ideas
- 0 Answers This code is working well locally, but fails sometimes when it is deployed. Why?
@WebService is a spring annotation
- shakesmove July 30, 2014
public class Calculator {
@WebService
public boolean isSumOdd(int sum1, int sum2) {
int result = 0;
result = sum1 + sum2;
if (result % 2 == 1) {
return true;
}
return false;
}
}
// The answer seems to be related that this singleton is not thread-safe but why I have to take care about syncronization ? Every thread doesn't pass his variable to this singleton to get the result? Doesn't it have in his switch context the state of the sum variables?
Does the thread share also the variable inside the scope of the method in a singleton so this could lead to problem? I was thinking that the variable are passed by value and copied and after a context switch the other thread has the possibility to restore his state but I believe that I am wrong.....| Flag | PURGE