设计模式---抽象工厂模式
来源:互联网 发布:数控编程指令g代码 编辑:程序博客网 时间:2024/06/05 05:58
#include<iostream>
using namespace std;
class User
{
private:
int id;
string name;
public:
int GetId()
{
return id;
}
void SetId(int _id)
{
this->id = _id;
}
string GetName()
{
return name;
}
void SetName(string name)
{
this->name = name;
}
};
class Department
{
private:
int id;
string name;
public:
int GetId()
{
return id;
}
void SetId(int _id)
{
this->id = _id;
}
string GetName()
{
return name;
}
void SetName(string name)
{
this->name = name;
}
};
class IUser
{
public:
virtual void Insert(User *user){}
virtual User *GetUser(int id){}
};
class SqlserverUser:public IUser
{
public:
void Insert(User *user)
{
cout<<"sql server sheet user insert"<<endl;
}
User *GetUser(int id)
{
cout<<"sql server sheet user insert"<<endl;
return NULL;
}
};
class AccessUser:public IUser
{
public:
void Insert(User *user)
{
cout<<"access sheet user insert"<<endl;
}
User *GetUser(int id)
{
cout<<"access sheet user insert"<<endl;
return NULL;
}
};
class IDepartment
{
public:
virtual void Insert(Department *department) {}
virtual Department *GetDepartment(int id){}
};
class SqlserverDepartment:public IDepartment
{
public:
void Insert(Department *user)
{
cout<<"sql server sheet Department insert"<<endl;
}
Department *GetDepartment(int id)
{
cout<<"sql server sheet Department insert"<<endl;
return NULL;
}
};
class AccessDepartment:public IDepartment
{
public:
void Insert(Department *user)
{
cout<<"access sheet Department insert"<<endl;
}
Department *GetDepartment(int id)
{
cout<<"access sheet Department insert"<<endl;
return NULL;
}
};
class IFactory
{
public:
virtual IUser *CreateUser(){}
virtual IDepartment *CreateDepartment(){}
};
class SqlServerFactory:public IFactory
{
public:
IUser *CreateUser()
{
return new SqlserverUser();
}
IDepartment *CreateDepartment()
{
return new SqlserverDepartment();
}
};
class AccessFactory:public IFactory
{
public:
IUser *CreateUser()
{
return new AccessUser();
}
IDepartment *CreateDepartment()
{
return new AccessDepartment();
}
};
int main()
{
User *user = new User();
Department *dept = new Department();
IFactory *fact= new AccessFactory();
IUser *iu = fact->CreateUser();
iu->Insert(user);
iu->GetUser(1);
IDepartment *id = fact->CreateDepartment();
id->Insert(dept);
id->GetDepartment(1);
return 0;
}
- 抽象工厂设计模式
- 设计模式-----抽象工厂
- 抽象工厂设计模式
- 抽象工厂设计模式
- 抽象工厂设计模式
- 设计模式 抽象工厂
- 设计模式--抽象工厂
- 设计模式--抽象工厂
- 设计模式 抽象工厂
- 设计模式-抽象工厂
- 设计模式-> 抽象工厂
- 抽象工厂设计模式
- 设计模式--抽象工厂
- 【设计模式】抽象工厂
- 设计模式---抽象工厂
- 【设计模式-抽象工厂】
- 设计模式-抽象工厂
- 设计模式--抽象工厂
- springmvc搭建时的神坑
- 原生select高度兼容ie7--css样式
- CODEVS-2050 派对灯
- 书的复制
- 01_Makefile文件编写
- 设计模式---抽象工厂模式
- 行内元素出现换行的情况
- Linux 目录结构与FHS标准
- 处理post请求乱码问题
- 1-5月知识总结
- Windows 微软雅黑(Microsoft YaHei)+ Monaco 字体整合方案
- JAVA将HTML转化图片最靠谱的方法
- 在phper中如何成为崛起最快的1%
- git操作