The creation mode consists of an object's interface and a specific class. This control class determines that the specific object is created when running, which is very useful in the log processing of the application, such as writing logs. In the file or in the database.
class Logger {virtual void LogError () = 0; virtual void LogError (CString strErr) = 0;}; class DBLogger: public Logger {public: void LogError () {// do here log} void LogError (CString strErr) {/ / do here log}}; Class Filelogger: Public logger {public: void logerror () {// do log here} {// do log here}}; class logfactory}}; class logfactory {private: Logfactory () { } Public: static logger * getLogger (ITYPE) {if (ITYPE == 1) Return new dblogger (); else return new filelogger ();}}; Class log {public: log () {plog = null; iodE = 1; Void settype (INT ITYPE) {IF (iType == ITYPE) Return; PLOG = logfactory :: getLogger (ITYPE); ITYPE = ITYPE;} void logerror () {PLOG-> LoGerror ();} void logerror Cstring strerror) {pLOG-> LoGerror (strerror);} private: Logger * PLOG; int itype;