An object is created when GetMsgHndlr is called for the first time and the subsequent call returns the created object. Advantage Applications can select the required message handler by passing the appropriate key. Only message handler class needs to be changed to include a new message handler. Disadvantage CMsgHndlr class should be aware of all its subclasses and include their header files, to create their objects. CMsgHndlr class is responsible for creating message handler objects based on the key passed to GetMsgHndlr method and this needs to be changed when a new message handler is added.
Application is forced to choose the required message handler class at link time.
CObject, the root class of MFC provides the support for Run-time class information and dynamic object creation. It ensures that the given Runtime class is of type CMsgHndlr and returns the created object. Advantage GetMsgHndlr can create object of CMsgHndlr or its descendants just with their Runtime class information, without having to know their exact class names. This method need not change when a new message handler subclass is created. Disadvantage Choice of the message handler class is made at link time.