美文网首页
GeekBand class8

GeekBand class8

作者: 0ffa31abb8f8 | 来源:发表于2016-12-11 12:44 被阅读0次

Shape * ashape =newCircle();

classMainForm :publicForm

{

ShapeFactory*  factory;//工厂public:

MainForm(ShapeFactory*factory)

{this->factory =factory;

}virtual~MainForm();voidMainCreate()

{//多态newShape * ashape =factory->CreateShape();//获取Noashape->GetNo();

}

};

classShape

{public:

Shape(intno =0) :no_(){}virtual~Shape(){}intGetNo(){returnno_; }intSetNo(intno_){}private:intno_;

};

classShapeFactory

{public:

ShapeFactory();virtualShape * CreateShape() =0;virtual~ShapeFactory(){}

};

classLine :publicShape

{public:

Line(){}virtual~Line(){}

};classRec :publicShape

{public:

Rec(){}virtual~Rec(){}

};classCircle :publicShape

{public:

Circle(){}virtual~Circle(){}

};

classLineFactory :publicShapeFactory

{public:

LineFactory();virtual~LineFactory();virtualShape*CreateShape()

{returnnewLine();

}

};classRecFactory :publicShapeFactory

{public:

RecFactory();virtual~RecFactory();virtualShape*CreateShape()

{returnnewRec();

}

};classCircleFactory :publicShapeFactory

{public:

CircleFactory();virtual~CircleFactory();virtualShape*CreateShape()

{returnnewCircle();

}

};

相关文章

网友评论

      本文标题:GeekBand class8

      本文链接:https://www.haomeiwen.com/subject/zgcpmttx.html