



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Suggested answer for Exercise 14.2A simple-minded implementation of the structure in Figure 14.8 is given below. It is apparent from the code that the abstract supplier interface has not been modified when the new abstract supplier interface was added, and hence that the module is closed. public interface AbstractSupplier public void operation() ;public interface NewAbsSupplier extends AbstractSupplier public void newOperation() ;public class ConcreteSupplier implements AbstractSupplier public void operation() System.out.println(ConcreteSupplier:operation() called) ; public class NewConcSupplier implements NewAbsSupplier public void operation() System.out.println(NewConcSupplier:operation() called) ; public void newOperation() System.out.println(NewConcSupplier:newOperation() called) ; public class Client AbstractSupplier supplier ; public Client(AbstractSupplier s) supplier = s ; public void doOperation() supplier.operation() ; public class NewClient NewAbsSupplier supplier ; public NewClient(NewAbsSupplier s) supplier = s ; public void doOperation() supplier.operation() ; public void doNewOperation() supplier.newOperation() ; Suggested answer for Exercise 14.5Observer Document/View class Observer class CView class ConcreteObserver class CMyView Observer.Update() CView.OnDraw() class Subject class CDocument class ConcreteSubject class CMyDoc Subject.Attach() CSubject.AddView() Subject.Detach() CSubject.RemoveView() Subject.Notify() CSubject.UpdateAllViews() Subject.SetState() CSubject.SetStateInfo() Subject.GetState() CSubject.GetStateInfo() This table shows that virtually every feature of Observer can be mapped into a corresponding feature of Document/View. There are two significant differences between the two patterns. Concrete observers hold a reference to their subjects, whereas in Document/View all references between views and documents are maintained at the abstract level. In practice, this is not very significant, and it can be argued that Document/View supports the association in Observer, as it is simply inherited from the bidirectional association linking the abstract classes. Another difference is the complexity of the update operation in Document/View. In Observer, the Notify() operation in the subject calls Update() in the observer, which in turn calls GetState(). In Document view, notification calls the OnUpdate() function, whereas it is a different function, OnDraw() which retrieves the document state. Again, however, it can be argued that Document/View does support the interaction defined in Observer, albeit in a not immediately straightforward way. There are therefore strong grounds for regarding Document/View as an instantiation of the Observer pattern. Suggested answer for Exercise 14.6This question should refer to the document/view architecture in addition to MVC. Figure 14.18 shows an MVC interaction where notification takes place every time the state of the subject (here the model) changes. In the document/view architecture, one option would be to have the operation CMyDoc:SetStateInfo() call OnUpdate() every time it are called. This approach has the advantage that client objects which are updating the document dont have to remember to call the notification operation, and the views are guaranteed to be automatically and promptly made consistent with the document or model state. On the other hand, if a number of consecutive updates are applied to a model, each will cause the corresponding views to be updated independently of the others. It may be sufficient to update the views once, at the end of this sequence of updates, and updating more frequently may be unacceptably inefficient. The alternative would be for objects which update the document to call UpdateAllViews() in the document/view architecture when the update is finished. This allows updates to wait until a sequence of changes has been made, but places an additional responsibility on client objects, thus complicating their implementation and
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 环境多参数融合监测-洞察与解读
- 2025北京石油学院附属实验小学招聘模拟试卷附答案详解
- 2025广东深圳大学人文学院董理副教授博士后招聘1人考前自测高频考点模拟试题及答案详解(必刷)
- 2025年及未来5年中国鹅绒被行业市场调研及未来发展趋势预测报告
- 2025年南平武夷山市公安局公开招聘铁骑女性警务辅助人员6人模拟试卷及答案详解(必刷)
- 2025湖南张家界市永定区发展和改革局招聘公益性岗位人员1人模拟试卷含答案详解
- 2025福建厦门市集美区宁宝幼儿园产假顶岗教师招聘1人模拟试卷及一套完整答案详解
- 2025巴州大学生乡村医生专项招聘计划预告考前自测高频考点模拟试题有答案详解
- 2025年春季湖南长沙市雨花区雨花实验第四小学实习教师招聘的考前自测高频考点模拟试题及一套完整答案详解
- 班组安全培训项目课件
- 大圆满前行考试题及答案
- 2025贵州毕节威宁自治县面向社会招聘城市社区工作者17人考试参考试题及答案解析
- 建筑工地垃圾清理与处理方案
- 修井现场安全培训内容课件
- 2022届辽宁省大连市高三一模语文试题
- 企业后备干部培养及管理办法
- 2025年标准服装行业安全员考试题库及答案
- 2025年宜昌专业技术人员公需科目培训考试题及答案
- 2025年成人高考高升专试题(含答案)
- 二年级语文上册第二单元大单元教学设计
- GB/T 42453-2023信息安全技术网络安全态势感知通用技术要求
评论
0/150
提交评论