BCC said:
I do indeed have 100 variables and each one is unique, but they are related.
So for example, I have groupings like this:
class CContainer {
m_circle_area;
m_circle_position;
m_circle_distance;
m_square_area;
m_square_position;
m_square_distance;
// etc, etc/
};
Each triplet then describes the properties of a particular type of object.
Conceptually, what I need to do is if my object is of type 'circle' it only
accesses the properties related to circle from the container class. Maybe
an analogy would help... Imagine a room where you have a chest of drawers.
Each drawer represents an object type, and contains all variables
related
to
that type. So the 'circle' drawer will have circle area, position, and
distance as well as maybe 'oval' area position and distance.
As a new object comes into the room, it opens the drawer corresponding to
its type and utilizes the variables it finds there. The object then leaves,
and new object comes in and opens its drawer (whether it be the same
type
or
not) and does its thing. This repeats.
So, every room needs a drawer with a full complement of properties for all
objects. Each drawer needs to contain only the properties relating to a
particular object, and properties are grouped according to the type of
object they represent.
At the moment, Im thinking about creating a class for each object just for
properties, and maybe putting all related property sets in an array
according to object type:
circle->circleArray[0].m_type;
circle->circleArray[0].m_area;
circle->circleArray[0].m_position;
etc.
I dont know though. Any thoughts on a good structure to use? Best way to
design this? Anything?
I'm wondering if it is similar to a problem I had initializing
cartesian-graph objects. A graph has a lot of variables - fonts, types of ax
es, maps to convert between scales, types of labels etc. In my case it was
really a whole lot of objects with a common owner working together. I did it
by having a separate class for holding all the properties with which I
wanted to initialize the graph. The problem was complex enough for the
properties class to have its own member functions, which were called by the
graph. I even had a hierarchy of properties classes, to match the hierarchy
of graph classes. Once it was all set up, the properties object was passed
to the graph, which set itself up by creating objects of many other classes
(axis objects, map objects, etc) according to the properties given to it.
Below is one such properties class. Note that this class has public member
variables, because it is more a bag of data than an object with behaviour. I
stress that I am not in the habit of making data members public, or even
protected.
class AxisGraphProperties
{
public:
enum AxisType
{
AXIS_NONE,
AXIS_PLAIN,
AXIS_TICKED,
N_AXIS_TYPES
};
public:
AxisGraphProperties();
virtual ~AxisGraphProperties();
public:
virtual ColorPool *GetColorPool() const = 0;
public:
virtual Vir1DMap *MakeDimensionMap(int nDim) const;
virtual Vir1DMap *MakeTraceDimensionMap(int nDim) const;
virtual AxisTickEngine *MakeAxisTickEngine(int nDim, const Vir1DMap
*pMap1D, AxisTickEngine *pRefTickEngine) const;
public:
AxisGraph *m_pGraph;
AxisType m_nAxisTypes[AxisGraph::N_EDGES];
vector_VirVal m_nAxisPriorityLabelPosns[AxisGraph::N_EDGES];
VirRect m_defaultScaleRect;
LogVal m_maxGraphLogLength;
LOGFONT m_lfGraphName;
LOGFONT m_lfAxisName;
LOGFONT m_lfTickLabel;
LOGFONT m_lfAnnotations;
int m_nAxisMaxLabels[VirPoint::N];
int m_nAxisLabelFieldWidth[VirPoint::N];
};
Even without definitions of most of the types used, you can probably get the
idea.
DW