RequestFactory: Share a method between the client and the server

33 views
Skip to first unread message

Sydney

unread,
Feb 11, 2012, 4:44:01 PM2/11/12
to google-we...@googlegroups.com
Hello, 

I want to run the same method on the client and server side. The reason is that the user can call that method when interacting with the UI, but the same method can also be called at a later time by a Task on the server side. I already wrote the method using the proxy object. I wanted to know if there is a way to call the same method on the server side (no proxy) without duplicating the code. 

What is the best practice?

Example:

MyObject is a domain object in the server package
MyObjectProxy is the proxy for MyObject

The method that uses the proxies called on the client side.
public static int sum(MyObjectProxy proxy) {
  return proxy.getA() + proxy.getB();
}

I want the same method but for the server side with the following signature:
public static int sum(MyObject domain) {
  return domain.getA() + domain.getB();
}

Thanks

Jakob Mar

unread,
Feb 12, 2012, 7:29:25 AM2/12/12
to Google Web Toolkit
Hello,

I do it like this:

public interface IMyObject{
public int getA();

public int getB();
}

public class MyObject implements IMyObject{
....
}

public interface MyObjectProxy extends EntityProxy,IMyObject{
...
}

public static int sum(IMyObject domain){
Reply all
Reply to author
Forward
0 new messages