global service handle OR multiple local handles

3 views
Skip to first unread message

Terry Weymouth

unread,
Mar 6, 2008, 4:37:29 PM3/6/08
to Google Web Toolkit
I have code like this in a lot of places...

service = (MyWebServiceAsync) GWT.create(MyWebService.class);
((ServiceDefTarget)
service).setServiceEntryPoint(GWT.getModuleBaseURL() +
MyWebApplication.serviceLocation);

the question is basically this; is it better to make service a global
variable, OR

value that I always get with something like MyWebServiceAsync service
= MyWebApplication.getService(), and keep in a
"static" local variable OR

just run the above code when every I need a link to the service...

or doesn't it matter?

Terry

Peter Blazejewicz

unread,
Mar 7, 2008, 5:05:40 PM3/7/08
to Google Web Toolkit
hi Terry,

it doesn't matter becuase it is used at compile time to create source
files for given implementation,

code implementation can be different and there are really as many
solutions as you can think including ServiceLocator pattern and
others,

for example GWT Designer from Instantiations creates such handy
serivce template code:

public interface MySerice extends RemoteService {
/**
* Utility class for simplifying access to the instance of async
service.
*/
public static class Util {
private static MySericeAsync instance;
public static MySericeAsync getInstance(){
if (instance == null) {
instance = (MySericeAsync) GWT.create(MySerice.class);
ServiceDefTarget target = (ServiceDefTarget) instance;
target.setServiceEntryPoint(GWT.getModuleBaseURL() + "MySerice");
}
return instance;
}
}
}

so your service is directly accessed later as
MyService.Util.getInstance(),

regards,
Peter
Reply all
Reply to author
Forward
0 new messages