MFC, STL and design mode?

zhaozj2021-02-08  181

MFC, STL and design mode?

Recently, I read "Design Mode" book, although I can't fully understand, it has benefited a lot. OOP programming ideas, can be described as profound, when learning and uses VC, in addition to need to understand conventional packages, inheritance, polymorphisms, plus the understanding and flexibility of multiple design patterns and flexible use to play VC object-oriented programming Powerful potential. In fact, the design pattern is not far away. You have used less than yourself in your programming practice, and the masters may not need to see this book, and you can sum up one by one. The MFC itself is a collection of Frameworks for multiple design patterns. When using the MFC, it is actually fill in some modes. Therefore, the MFC and its source code are an excellent textbook for learning OOP and design patterns. I wonder myself, some of the MFCs have a high design mode of frequencies, and they will be terminated, and they can only list one or two due to limited personal abilities and reference materials. Interested comrades can participate in the post on the VC version: http://www.9cbs.net/expert/topic/159/159235.shtm ● Iterator intent: provide a method sequence to access a aggregate object Each element, but does not need to expose the internal representation of the object. Example: Containers in STLs are provided with the ITerator STL, providing many total data structures, which have also defined many unified iterators for these data structures, and access the element of the data structure through the iterator. This separates the access of the data to the internal storage structure of the data, so that all data structures have a common access method. ● Template Method intent: Define the skeleton of the algorithm in an operation, and delay some steps into the subclass. Template Method allows subclasses to redefine certain specific steps of the algorithm without changing the structure of an algorithm. Example: This mode is used in a large number in the MFC source code. Typical: CView base class corresponding Void cPAINTDC DC DC DC (this); onpreparedc (& DC); OnDraw (& DC);} then derived " Complete the specific steps. ● Bridge intent: Separate the abstraction section with its implementation, so that they can change independently. Example: SERIALIZATION sequence mechanism In serialization mechanism, CARCHIVE and CFILE completed the permanent storage of data for data, CARCHIVE defined the shared interface of data access and CFILE and its derived classes completed the specific implementation of the stored procedure. (Document, memory buffer, etc.) This, the interface portion of the data store is separated from the specific implementation portion. Give CARCHIVE with different CFILE derived classes that can be different physical storage. ● Observer intent: Define a one-to-many dependency between the objects, and all objects that depend on its object are notified when the status of an object changes. Example: Document View Structure in the MFC A document object can correspond to multiple view objects, and the view object is an interpretation of the document object. When the document object changes, call the UpdateAllViews update view and then the ONUPDATE of each view is called.

● Chain of Responsibility (duty chain)

intention:

Many objects have the opportunity to handle the request, thereby avoiding the coupling relationship between the requested sender and the recipient. Connect these objects into a chain and deliver the request along this chain until there is an object to process it.

Example:

MFC message chain

In the MFC, each ccmdtarget derived class defines the response action of a particular message and command.

The message and command are passed along the chain defined by the message map until there is an object to handle him.

In addition, I feel that the definition of the document template in the DOC-View document structure should be a model, but it is still not summarized.

It is that kind.

Also, the dynamic generation of COBJECT derived class is also whether it is a model. Also think of the high guidance!

Amazing: mountebank, wonder88, mountebank, bzshow ...

转载请注明原文地址:https://www.9cbs.com/read-3135.html

New Post(0)