



全文預(yù)覽已結(jié)束
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(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. 本站所有資源如無特殊說明,都需要本地電腦安裝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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 開式、閉式泵的工作原理和調(diào)試方法
- 交通勸導(dǎo)面試題及答案
- 2025年 廣西高校畢業(yè)生“三支一扶”計(jì)劃招募考試試卷附答案
- 手工香皂產(chǎn)品營(yíng)銷活動(dòng)
- 治未病科健康宣教課件
- 認(rèn)識(shí)自己小學(xué)心理健康
- 2025年中國(guó)女士格子襯衫行業(yè)市場(chǎng)全景分析及前景機(jī)遇研判報(bào)告
- 學(xué)校安全教育匯報(bào)材料
- 《數(shù)智時(shí)代下的供應(yīng)鏈管理:理論與實(shí)踐》課件 第二章 供應(yīng)鏈管理焦點(diǎn)與核心理念
- 卷材車間技師培訓(xùn)
- 2025年圍產(chǎn)期保健工作計(jì)劃
- 戰(zhàn)地記者職業(yè)生涯規(guī)劃
- 2022-2023學(xué)年北京市懷柔區(qū)八年級(jí)(下)期末語文試卷
- 夏令營(yíng)安全管理工作制度
- 5【選必下】高中語文部編版教材選必下冊(cè)課內(nèi)文言文精練
- 實(shí)驗(yàn)室安全教育課件
- 2024年知識(shí)競(jìng)賽-《民用爆炸物品安全管理?xiàng)l例》知識(shí)競(jìng)賽考試近5年真題集錦(頻考類試題)帶答案
- 國(guó)畫基礎(chǔ)知識(shí)題庫(kù)單選題100道及答案解析
- 《改革開放史》教學(xué)大綱
- 透析病人不安腿綜合征
- 15S202 室內(nèi)消火栓安裝
評(píng)論
0/150
提交評(píng)論