第11讲架构与其他模式内容摘要:
tion model is required. Not a Swing or GUI class. Just a plain object which the GUI objects Shanghai Jiaotong University 3. 更多模式 Shanghai Jiaotong University 使用模式解决某些实际问题 : Reliability and recovery Local caching Handling failure Handling payments 7个新模式 2020/11/4 38 Shanghai Jiaotong University 采用适配器和多态模式实现缓存 2020/11/4 39 interface IProductsAdapter getSpecification( itemID ) : ProductSpecification DBProductsAdapter getSpecification( itemID ) LocalProducts remoteProductsService: IProductAdapter getSpecification( itemID ) BigWebServiceProductsAdapter getSpecification( itemID ) 1 1 Implements the adapter interface, but is not really an adapter for a second ponent. Rather, it itself implements the local service function. ProductCatalog productsService : IProductAdapter getSpecification() 1 1 Shanghai Jiaotong University Singleton 和 Factory 提供了实现接口的类 2020/11/4 40 :Store :Register pc: ProductCatalog create() 2: create(pc) 1: create() singleton :ServicesFactory psa : LocalProducts externalService : DBProductsAdapter : psa := getProductsAdapter() IProductsAdapter : create( externalService ) : create() 本地服务获取了对外部服务的适配器的引用 IProductsAdapter 返回本地服务 Shanghai Jiaotong University 从缓存或者数据库中获取产品信息 2020/11/4 41 : LocalProducts remoteService : DBProductsAdapter IProductsAdapter : KeyIndexedFileOf SerializedObjects 1: ps := get( id ) 3 [not in file ]: put( id, ps ) ps := getSpecification(id) 2 [not in file] : ps := getSpecification(id) continued in another diagram IProductsAdapter Shanghai Jiaotong University 处理故障 本地缓存中未命中且访问外部产品服务失败时,如何处理 ? 用信号通知收银员人工输入价格和描述 ? 取消输入该商品项 ? 解决方案 : 抛出异常 低层的异常转换成高层次中有意义的异常 依据问题而不是抛出者命名异常 2020/11/4 42 Shanghai Jiaotong University 处理错误 (seq diagram) 2020/11/4 43 exception DBUnavailableException() : DBProducts Adapter IProductsAdapter : Persistence Facade UML notation : * All asynchronous messages, including exceptions, are illustrated with a stick arrowhead. * Exceptions are shown as messages indicated by the exception class name. * An optional exception or signal stereotype is legal (an exception is a kind of signal in the UML), if increased visibility is desired. ps := get(...) ps := getSpecification(id) : Object resultSet := executeQuery(...) exception SQLException() note the difference between synchronous and asynchronous message arrowheads in the UML recall that indicating the instance of type Object is useful when one wants to indicate the interface, but not the class of an instance exception ProductInfoUnavailableException() stopping the message line at this point indicates the PersistenceFacade object is catching the exception Shanghai Jiaotong University Exceptions in a UML class diagram 2020/11/4 44 exceptions caught are modeled as a kind of operation handling a signal PersistenceFacade usageStatistics : Map Object get(Key, Class) throws DBUnavailableException, FatalException put(Key, Object) { throws= (DBUnavailableException, FatalException) } ... 玸 ignal?SQLException() 玸 ignal?IOException() exceptions FatalException DBUnavailableException exceptions thrown can be listed in another partment labeled exceptions UML notation : The UML has a default syntax for operations. But it does not include an official solution to show exceptions thrown by an operation. There are at least three solutions: 1. The UML allows the operation syntax to be any other language, such as Java. In addition, some UML CASE tools allow display of operations explicitly in Java , Object get(Key, Class) throws DBUnavailableException, FatalException 2. The default syntax allows the last element to be a property string. This is a list of arbitrary property+value pairs, such as { author=Craig, kids=(Hannah, Haley), ...}. Thus, put(Object, id) { throws= (DBUnavailableException, FatalException) } 3. Some UML CASE tools allow one to specify (in a special dialog box) the exceptions that an operation throws. Shanghai Jiaotong University 更多模式 转换异常 对问题而不是抛出者命名 集中错误日志 错误会话 代理 抽象工厂 自力更生 2020/11/4 45 Shanghai Jiaotong University (1)转换异常 将较低层的异常转换为本层次系统中有意义的异常 通过转换,高层次的异常提供了对低层次异常的子系统层次的解释 2020/11/4 46 Shanghai Jiaotong University (2)命名问题,而不是抛出者 异常必须依据其抛出的理由进行命名 抛出者并不能表示问题所在 2020/11/4 47 Shanghai Jiaotong University (3)集中错误日志 使用单实例类访问的集中错误日志对象,所有的异常都向它汇报 提供了一致性 对输出流和格式的柔性定义 2020/11/4 48 Shanghai Jiaotong University (4)错误会话 使用标准的单实例类访问的、应用程序无关的、非用户界面的对象向用户通知错误。 对输出机制的变化实现了防止变异 一致的错误汇报风格 集中控制公共的错误通知策略 性能也有所改进 2020/11/4 49 Shanghai Jiaotong University 处理异常 2020/11/4 50 : DBProducts Adapter : Local Products IProductsAdapter :ProductCatalog ps := getSpec(id) :Register enterItem(id, qty) :ProcessSale Frame exception ProductInfoUnavailableException() singleton :ErrorDialog notify(message, exception) ps := getSpec(id) ps := getSpec(id) continued singleton :ErrorDialog notify (message, exception) * : notify(message) : Object : Object INotifier GUI dialog box text console dialog speech dialog singleton :Log log(exception) IProductsAdapter Convert Exception pattern Error Dialog pattern Centralized Error Logging pattern Shanghai Jiaotong University (5)代理 (GoF) 问题 : 不希望或不可能直接访问真正的主题对象时,应该如何 解决方案 : 通过代理对象增加一层间接性,代理对象实现与主题对象相同的接口,并且负责控制和增强对主题对象的访问 2020/11/4 51 Shanghai Jiaotong University Proxy 结构 2020/11/4 52 interface ISubjectInterface foo() RealSubject foo() { ... preprocessing () ... postprocessing } Client subject : ISubjectInterface doBar() 1 1 1 1 Proxy realSubject : ISubjectInterface foo() { ... whatev。第11讲架构与其他模式
相关推荐
把一个未经控诉、未经法律制裁的公民判处死刑的话,我们就要把这些法官当作杀人犯来惩罚。 在我们这儿,老是有两党用笔或用阴谋斗争着;然而,到了武装保护国家和自由的紧要关头,这两党又团结起来了。 这两党互相监督着;他们互相阻止侵犯法律的神圣性;他们互相憎恨,但是他们都爱国家 —— 这是两个醋气熏天的情夫在争献殷勤地侍奉同一个情妇。 —— 《巴比伦公主》 返 回 返 回第 11课 综合探究课
getFloat(int ColumnIndex) 返回指定字段的以 Java的 float类型表示的字段值 double getDouble(int ColumnIndex) 返回指定字段的以 Java的 Double类型表示的字段值 BigDecimal getBigDecimal(int ColumnIndex , int scale) 返回指定字段的以
民工荒出现的启示 农业的贡献 农村人口向非农产业转移是中国现代化的最大难题 中国农业人口占总人口的将近 60%,近几年城市化水平每年提高一个百分点以上,到 2020年城市化水平大概能够达到 60%。 现在中国就业人口有 7亿,比所有发达国家就业人数的总和还要多。 7亿就业人口中,城市 2亿以上,农村将近 5亿。 现在农村好多地方还是手工劳动,即使在目前的技术水平下,农村也还有
脉冲下,数据按位传输,并且高位在前、低位在后,是一种全双工通信。 数据传输速度总体上来说比 I2C总线要快,速度可以达到几 Mbit/s。 • SPI 的工作模式有两种:主模式和从模式, 无论 哪种 模式 ,都支持 3Mbit/s的速率,并且还具有传输完成标志和写冲突保护标志。 • 接口一般使用四条线:串行时钟线 SCK、主器件输入 /从器件输出数据线 MISO、主器件输出
容和教学目标之间的关系 知识 理解 应用 分析 综合 评价 问题 原理 技能 概念 事实 教学网站的设计 对于一个提供网络教育的教学网站来说,至少应该包含以下几个方面的内容: 课程介绍 课件和课程材料 参考资料列表 多媒体教学材料 课程计划 班级计划 教学手册 选课系统 常见问题 咨询 教师和学生名册 教学过程结构的设计