• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            C++ Programmer's Cookbook

            {C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

            MFC與設計模式

            This main topic of this article is to show how patterns are used in MFC. We will be seeing the usage of three patterns in MFC library.

            Creational : Singleton Pattern

            First step in any MFC application is the creation of application object (object of class derived from CWinApp). There should be only one application object in an instance of MFC application. CWinApp is designed to make sure that only application object is present in a given instance. CWinApp and its descendants are called Singleton Classes. A class (CWinApp or its descendant) that assures a maximum of ONE object of its type at a given time and provides a global access point (AfxGetApp() method) to this object is a Singleton class.

            As this principle is applied over and over again to solve recurring object "creational" problems, this becomes a pattern. Singleton Pattern ensures that a class only has one instance and provides a global access point it. The article Creating Singleton Objects using Visual C++ talks about different approaches for implementing Singletons.

            Structural : Bridge Pattern

            Bridge Pattern is all about decoupling an abstraction (interface) from its implementation so that the two can vary independently. In MFC, the process of storing/retrieving an object to/from a persistence mechanism (like a file) is called Serialization. MFC uses the Bridge Pattern to implement Serialization. CArchive and CFile classes implement object Serialization. CArchive class provides the interface for writing/reading an object to/from a persistence mechanism whereas the CFile and its sub classes provides implementation for different persistence mechanisms such as memory, disk file, sockets etc.

            A CArchive object is configured with an object of class CFile (or a derived class) during its construction, from which it obtains the necessary information for serialization, including the filename and type of the requested operation (a read or write). Client performing the Serialization operation can use CArchive object without regarding the persistence mechanism implemented by CFile classes.

            The article Bridge Pattern - Bridging the gap between Interface and Implementation talks about Bridge pattern in detail.

            Behavioral : Observer Pattern

            The Observer Pattern is intended to "Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically". An object that is subjected to change is called a Subject and an object that depends on the Subject's state is called an Observer.

            MFC uses a Document/View variant of the Observer Pattern. MFC's famous Document/View architecture uses this variant. A document contains the data object and acts as a Subject. A view is a window object through which the user updates the document and it acts as an Observer. A document can have multiple views. Whenever the data in the document is changed by one of the views, it updates the document by calling UpdateAllViews method, with optional hint about the modification. To inform about the change to other views, the document object calls OnUpdate method for each view attached to it (except the view that called UpdateAllViews). Derived view classes can override the OnUpdate method and update themselves by querying the data from the document.

            The article Applying Observer Pattern in C++ Applications talks about Observer pattern in detail.

            Summary

            Design Pattern provides a common language for designers and helps them to decompose systems into a set of cooperating classes and objects. They provide proven design solution to recurring problems. In this article, I have introduced the design pattern and how MFC is using some of the patterns in its design. We can easily find more and more patterns when we dig into MFC and its classes.

            posted on 2006-05-25 13:39 夢在天涯 閱讀(3778) 評論(0)  編輯 收藏 引用 所屬分類: CPlusPlusMFC/QTDesign pattern

            公告

            EMail:itech001#126.com

            導航

            統計

            • 隨筆 - 461
            • 文章 - 4
            • 評論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1807518
            • 排名 - 5

            最新評論

            閱讀排行榜

            亚洲色欲久久久综合网| 亚洲欧洲久久av| 久久99国内精品自在现线| 无码精品久久久天天影视| 2021久久精品国产99国产精品| 国产一久久香蕉国产线看观看| 亚洲国产天堂久久综合网站| 久久久久亚洲精品天堂久久久久久 | 色老头网站久久网| 久久99精品久久久久婷婷| 久久久青草青青亚洲国产免观| 中文字幕亚洲综合久久菠萝蜜| 色妞色综合久久夜夜| 久久综合伊人77777麻豆| 亚洲欧美日韩中文久久| 91久久成人免费| 久久香综合精品久久伊人| 国产日韩久久免费影院| 久久不射电影网| 狠狠色丁香婷婷久久综合| 久久www免费人成看国产片| 狠狠色婷婷综合天天久久丁香| 久久青青草原精品国产软件| 久久人妻少妇嫩草AV无码专区| 亚洲精品无码久久久久去q | 久久精品免费一区二区| 人妻中文久久久久| 久久久久国产一级毛片高清板| 91亚洲国产成人久久精品网址| 久久久久se色偷偷亚洲精品av| 久久亚洲电影| 狠狠色综合久久久久尤物| 国产日产久久高清欧美一区| 久久99国产精品尤物| 亚洲午夜久久久影院伊人| 久久人做人爽一区二区三区| 亚洲人成无码www久久久| 香蕉久久AⅤ一区二区三区| 亚洲国产成人精品91久久久| 亚洲欧洲久久久精品| 久久人人爽人人爽人人片AV高清 |