2012年7月25日

简单factory

摘要: 参数化工厂模式,可以解决两种问题:1.封装对对象的创建2.推迟化对象的创建//工厂生产的一类产品class TypeBase{public: TypeBase(); virtual ~TypeBase(); virtual void Speak() = 0;};TypeBase::TypeBase(){}TypeBase::~TypeBase(){}//某两种具体产品#include"typebase.h"class IntType:public TypeBase{public: IntType(); ~IntType(); void Speak();pri... 阅读全文

posted @ 2012-07-25 17:46 sprzhing 阅读(230) 评论(0) 推荐(0) 编辑

Singleton

摘要: 单体模式主要用于在纯面向对象编程中在内存中维持一个唯一的全局对象。#include<QString>#include<QDebug>class Singleton{protected: Singleton();public: static Singleton* GetInstance(); void Speak();private: static Singleton* m_Instance; QString sentence;};该程序是在Qt环境下编写,cpp文件内容如下:#include "singleton.h"Singleton* Singl 阅读全文

posted @ 2012-07-25 16:30 sprzhing 阅读(233) 评论(0) 推荐(0) 编辑

导航