Client server design pattern

December 18, 2015
As browser technologies (HTML

In our project, we have done exactly what you are looking for: a single RPC function which transports wrapped requests to the server, the server executes the corresponding code, and then returns the result to the client again. How much of that is smelly code - I am not sure. But here's a brief summary of what we did:

RPC function:

public

where Command and CommandReturnValue are empty interfaces extending com.google.gwt.user.client.rpc.IsSerializable. Every command implementation has its corresponding CommandReturnValue-implementation, which can wrap any GWT-serializable objects.

Example CommandReturnValue:

public class SaveCommandReturnValue implements CommandReturnValue{ private String errorMessage; // getter and setter and other important information to return }

Example Corresponding Command:

public class SaveCommand implements Command{ private List stringsToSave; // other serializable fields and their getters + setters }

The server-side implementation of the RPC-function then dispatches the call depending on the command-class. In our case, we have an implementation class for every command (implementing CommandImplementation).

Example Implementation:

public class SaveCommandImpl implements CommandImplementation{ @Override public SaveCommandReturnValue execute(SaveCommand command){ // code to save whatever the command says to save } }

We use Spring on our server-side, so it's a simple thing to register the implementation as a Spring-bean and annotate the Command with the Spring-bean-name. The dispatcher first searches the incoming command for the Spring-bean-name annotation, fetches the correct CommandImplementation-bean from the application context, and then calls the bean's 'execute' method.

Source: stackoverflow.com
RELATED VIDEO
Java Springs | AJAX | MVC Design Pattern | Singleton
Java Springs | AJAX | MVC Design Pattern | Singleton ...
Singleton Pattern - PHP Design Patterns
Singleton Pattern - PHP Design Patterns
RELATED FACTS
Share this Post