Interview Question for Software Engineer / Developers
- -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 October 04, 2014 in Germany for Devoper
Could it be useful the prototype pattern? If yes why?| Report Duplicate | Flag | PURGE
Software Engineer / Developer Ideas
Country: Germany
Interview Type: In-Person