A follow up to another question (Making a design decision about reading model data from an input file).
I wish to ask another question regarding builder or factory pattern. (I read that builder is more complex than factory, and I may not need to use builder for now). So here is the data I have to read:
TABLE: "DEGREES OF FREEDOM"
X=Yes Y=Yes Z=Yes R1=Yes R2=Yes R3=Yes
TABLE: "ANALYSIS OPTIONS"
Solver=Advanced SolverProc=Advanced
TABLE: "COORDINATE SYSTEMS"
Name=GLOBAL Type=Cartesian X=0 Y=0 Z=0
TABLE: "GRID LINES"
CoordSys=GLOBAL AxisDir=X GridID=A XRYZCoord=-720 LineColor=Gray8Dark Visible=Yes
CoordSys=GLOBAL AxisDir=X GridID=B XRYZCoord=-432 LineColor=Gray8Dark Visible=Yes
CoordSys=GLOBAL AxisDir=X GridID=C XRYZCoord=-144 LineColor=Gray8Dark Visible=Yes
CoordSys=GLOBAL AxisDir=X GridID=D XRYZCoord=144 LineColor=Gray8Dark Visible=Yes
CoordSys=GLOBAL AxisDir=X GridID=E XRYZCoord=432 LineColor=Gray8Dark Visible=Yes
CoordSys=GLOBAL AxisDir=X GridID=F XRYZCoord=720 LineColor=Gray8Dark Visible=Yes
...
There are many more tables like these. Some tables have parent, child relationships (Each coordinate system has grid line of its own). I have made structures that represent each table, like this:
struct ActiveDOF
{
bool Ux;
bool Uy;
bool Uz;
bool Rx;
bool Ry;
bool Rz;
};
struct GridLine
{
enum Direction{X, Y, Z};
enum Type{PRIMARY, SECONDARY};
enum Location{START, END};
std::string coodSystem;
Direction direction;
std::string gridID;
float XRYZ;
Type lineType;
QColor color;
bool visible;
Location bubleLoc;
bool allVisible;
float bubleSize;
};
struct CoordinateSystem
{
std::string name;
std::string type;
QVector3D center; // center x, center y, cetner z
QVector3D about; // aboutx, about y, about z
std::vector<GridLine> gridLines;
};
these data structures are incorporated to the model class, which will make a huge class since there are 50 odd data structures like this:
class Model
{
private:
ActiveDOF activeDOF;
CoordinateSystem coordinateSystem;
....
public:
Model() {} ...
}
each table has to have its set method and get method. This design worries me because if I decide to change it, it is going to be very time consuming. I appreciate any suggestion. I think the information here also will put the earlier question in a better light.
Now, I don't know where the builder or factory method should go, given the situation. I looked at some code and UML charts but I was not able to understand how to implement the factory, or builder to make structures required for my design. I have to have access to each table by name, because they might be subject to change inside the model, so for the time being I am avoiding making each of them a subclass of a virtual base class, so that I can store them in a container.
Also, does it make sense that instead of declaring an instance of the data struct, I should keep a pointer to them ? if all data structures are derived from a virtual base class called Record, then the model will be something like this:
class Model
{
private:
ActiveDOF* activeDOF;
CoordinateSystem* coordinateSystem;
....
std::Vector<Record*> data;
public:
Model() {} ...
}
I think it is extra work to allocate, dislocate memory for them, but it can help in managing the data and keep extra typing ? am I right in assuming that ?