R
Rajiv Das
I have run into a design time problem and I look for help.
This is the crux of the design. [Representative]:
class IShape{
public:
virtual void Draw() = 0;
};
class Circle : public IShape{
private:
float _center, _radius;
public:
Circle(float a, float b):_center(a),_radius(b){}
virtual void Draw(){/*Draw it*/}
};
class Square : public IShape{
private:
float _length;
public:
Square(float a):_length(a){}
virtual void Draw(){/*Draw it*/}
};
Constraints:
1. I need to create dynamic collections of different shapes.
2. New shapes made available through plug-ins can be used.
3. New Collections can be defined at run-time.
3. Different shapes can have different constructor parameter lists.
Usage:
typedef std::vector<IShape*> ShapeCollection ;
typedef std::vector<ShapeCollection*> AllShapes;
AllShapes g_MyCollection;
/*based on client layer request create a new collection*/
g_MyCollection.push_back(new ShapeCollection);
g_MyCollection[0]->push_back(new Circle(0.0f, 1.4f));
g_MyCollection[0]->push_back(new Square(5.5f));
My questions are:
1. Should each shape register itself with a factory that supports
variable parameters in the constructor?
[e.g.
http://www.gamedev.net/reference/programming/features/objectfactory/page3.asp]
2. Should all ShapeCollections register themselves in a registry?
[e.g. defineCollection(array of shapes...how do we take care of
parameters??]
Help
Thanks
Rajiv
This is the crux of the design. [Representative]:
class IShape{
public:
virtual void Draw() = 0;
};
class Circle : public IShape{
private:
float _center, _radius;
public:
Circle(float a, float b):_center(a),_radius(b){}
virtual void Draw(){/*Draw it*/}
};
class Square : public IShape{
private:
float _length;
public:
Square(float a):_length(a){}
virtual void Draw(){/*Draw it*/}
};
Constraints:
1. I need to create dynamic collections of different shapes.
2. New shapes made available through plug-ins can be used.
3. New Collections can be defined at run-time.
3. Different shapes can have different constructor parameter lists.
Usage:
typedef std::vector<IShape*> ShapeCollection ;
typedef std::vector<ShapeCollection*> AllShapes;
AllShapes g_MyCollection;
/*based on client layer request create a new collection*/
g_MyCollection.push_back(new ShapeCollection);
g_MyCollection[0]->push_back(new Circle(0.0f, 1.4f));
g_MyCollection[0]->push_back(new Square(5.5f));
My questions are:
1. Should each shape register itself with a factory that supports
variable parameters in the constructor?
[e.g.
http://www.gamedev.net/reference/programming/features/objectfactory/page3.asp]
2. Should all ShapeCollections register themselves in a registry?
[e.g. defineCollection(array of shapes...how do we take care of
parameters??]
Help
Thanks
Rajiv