我使用了一个抽象基类来实现接口和派生类。请参阅下面的代码。它可以与c ++中的任何标准设计模式相关联吗?
Class people
{
public:
virtual void setname(string name)=0;
virtual void SetAge(int Age)=0;
//etc consists of only pure virtual functions like above
};
Class Students: public people
{
void setname(string name)
{
//implementation of the function
}
void SetAge(int Age) { //implementation }
}
我已经定义了上面的许多类,并且在Buildclass的构造函数中创建了对象:
Buildclass::Buildclass()
{
people *Obj = (people*) new Students();
interface *obj1 = (interface*) new implementation();
}
我已经提供了上面的getinstance函数以用于另一层
void BuildClass::getPeopleinstance()
{
return Obj;
}
void BuildClass::getAnotherinstance()
{
return Obj1;
}
上述代码可以与任何设计模式相关联吗?请告诉我?我无法找到。
答案 0 :(得分:4)
您似乎正在使用工厂模式,但这无关紧要。专注于编写好的代码,而不是设计模式。