public class Client { public int process(Params params) { Server server = Server.getInstance(); Data data = server.retrieveData(params); ... }}
public class Client { private final Server server; public Client(Server server) { this.server = server; } public int process(Params params){ Data data = this.server.retrieveData(params); ... }}
public void testProcess() { Server mockServer = createMock(Server.class); Client c = new Client(mockServer); assertEquals(5, c.process(params));}
To be honest, I do not see the advantage...With the first implementation of the Client-Class, it would have been possible to do:Client c = new Client();client.process();That's all... what's the drawback here?
To be honest, I do not see the advantage...
ReplyDeleteWith the first implementation of the Client-Class, it would have been possible to do:
Client c = new Client();
client.process();
That's all... what's the drawback here?