扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:中国IT实验室 来源:中国IT实验室 2007年9月23日
关键字:
在本页阅读全文(共6页)
下图展示了整体 MVC 和界面的体系结构:
|
MVC 和界面模式定义了应用程序的整体结构。另外,Smart Ticket 也列出了一些重要的行为模式,这些模式能帮助开发人员提高效率。
The RemoteModelProxy 类把每一个请求动作都委托给 handler 类链,以便透明地解决 RMS 串行化和 HTTP 连接的异常管道。 链接的处理程序体系结构基于实现它的 RequestHandler接口和 RemoteModelRequestHandler 抽象类:
public interface RequestHandler {
RequestHandler getNextHandler();
void init() throws ApplicationException;
void destroy() throws ApplicationException;
}
abstract public class RemoteModelRequestHandler
implements RequestHandler, RemoteModel {
private RemoteModelRequestHandler nextHandler;
private Preferences preferences;
protected static ProgressObserver progressObserver;
public RemoteModelRequestHandler(
RemoteModelRequestHandler nextHandler) {
this.nextHandler = nextHandler;
}
public RequestHandler getNextHandler() {
return nextHandler;
}
public void init() throws ApplicationException {
if (nextHandler != null) {
nextHandler.init();
}
return;
}
public void destroy() throws ApplicationException {
if (nextHandler != null) {
nextHandler.destroy();
}
return;
}
public void login(String userName, String password)
throws ModelException, ApplicationException {
getRemoteModelRequestHandler().login(userName, password);
return;
}
public void createAccount(AccountInfo accountInfo)
throws ModelException,
ApplicationException {
getRemoteModelRequestHandler().createAccount(accountInfo);
return;
}
// Other action methods declared in RemoteModel
// ...
}
|
具体的 handler 类扩展了 RemoteModelRequestHandler 类。嵌套的构造函数建立一个处理程序链。Smart Ticket 启用了两个处理程序类:RMSCacheHandler 和 HTTPCommunicationHandler。因此链接装配方法如下:
public class RemoteModelProxy extends ModelObjectLoader
implements RemoteModel {
private RemoteModelRequestHandler requestHandlerChain;
private Preferences preferences = null;
private Hashtable movies = new Hashtable();
public RemoteModelProxy(String serviceURL)
throws ApplicationException {
requestHandlerChain =
new RMSCacheHandler(
new HTTPCommunicationHandler(null, serviceURL));
return;
}
// ...
public Movie getMovie(String movieKey)
throws ModelException,
ApplicationException {
Movie movie = (Movie) movies.get(movieKey);
if (movie == null) {
movie = requestHandlerChain.getMovie(movieKey);
movies.put(movieKey, movie);
}
return movie;
}
// Other methods ...
}
|
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。