



全文預(yù)覽已結(jié)束
下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年北京裝飾裝修合同范本
- 慢阻肺護(hù)理查房
- 小班愛(ài)眼護(hù)眼活動(dòng)總結(jié)
- 藥物滲漏不良事件分析
- 2025年人力資源管理試題含答案
- 膜性腎病的臨床護(hù)理
- 醫(yī)學(xué)人衛(wèi)教材配套建設(shè)要點(diǎn)
- 人音版小學(xué)音樂(lè)五年級(jí)上冊(cè)《外婆的澎湖灣》教學(xué)設(shè)計(jì)
- 七年級(jí)英語(yǔ)語(yǔ)法總結(jié)模版
- 教室衛(wèi)生大掃除活動(dòng)總結(jié)模版
- 高校學(xué)生資助誠(chéng)信教育主題活動(dòng)
- 跨國(guó)公司海外人力資源外包與派遣管理合同
- LNG 加氣站防雷安全培訓(xùn)與應(yīng)急演練記錄 202505
- 普惠金融專員試題及答案
- 【課件】認(rèn)識(shí)民法典+課件統(tǒng)編版道德與法治七年級(jí)下冊(cè)
- 2025年航天知識(shí)競(jìng)賽題庫(kù)及答案
- 2025年人教版小學(xué)小升初科學(xué)模擬試卷(含答案解析)
- 腸易激綜合征中西醫(yī)結(jié)合診療專家共識(shí)(2025)解讀課件
- 中國(guó)腫瘤營(yíng)養(yǎng)治療指南
- 蘇教版三年級(jí)下冊(cè)科學(xué)實(shí)驗(yàn)題
- 員工分紅合作協(xié)議書(shū)54559
評(píng)論
0/150
提交評(píng)論