Original Post
Ok... I find myself in a major quandry. I began this project by setting up classes as follows:
Notice that the objects are on the heap and I am creating an array of pointers to those objects. Now, for some of my collections... I created STL lists instead... for example:
The result is similar in that I end up with a list of pointers to objects that are created on the heap.
My problem with method one stems from the fact that a lot of times these classes need to grab information (either data or results of functions) from many other classes. What's worse, there are often times when I have to cascade through a number of classes to do this. For example, A is a B which is of type C. A now needs to get data from C via it's relationship with B. I realize that I can create a function in A which retrieves a function in B which retrieves a function in C... but my problem is as follows.
If we are storing the relationships between A-B and B-C as index IDs for the BCollection and CCollection objects, we need to have a reference to those collections. If A needs to ask BCollection about a particular B, I need to have passed in a reference to BCollection. Subsequently, the call to B (from BCollection) will need to have a reference to CCollection so that B can get the data (eventually) from C. It would seem that the original call to A would have to have references to BCollection AND CCollection.
When I shifted to using pointers instead, I didn't have to have A go through BCollection but rather called a function of B directly using mMyData = B->MyFunction(); B->MyFunction() could then call C directly by pointer using return C->CsFunction(); I thought my problem was solved.
Of course, then I realized that I have no way of loading data from the file that says A is of this specific type of B. I had originally stored the index of BCollection that A was refering to... obviously I can't store the pointer the same way. I made a quick effort to change my data load function to ask BCollection to return the pointer to a B object when I gave it the index to the array. However, I had originally been calling the data load function of ACollection in its constructor and I ran into some issues so I quickly backed out my changes prior to rethinking the issue.
That brings me to you guys...
I have many objects here to deal with with some very complicated relationships between them. At times, they may need to access data/functions from many different other objects of other classes. I am loathe to have all my function calls passing around &references to very many different classes unless that is the best way to go.
How is this sort of issue generally handled? Is it common to pass references to 4-6 different class objects around at all times? Is there any value to creating a master object to pass around where the various collection objects are members of it? Are pointers the way to go instead so I can just get directly to the specific object I want to store as member data? If so, what is a good technique for saving references such as that in data files other than how I mentioned (saving an index to an array of pointers and converting the index to the actual pointer as you load it)?
Your help would be appreciated!
Dave Mark - President and Lead Designer
Intrinsic Algorithm - "Reducing the world to mathematical equations!"
RIPPL Sports - NFL Statistical Analysis and Prediction System
[edited by - InnocuousFox on January 24, 2003 5:50:21 PM]
[edited by - InnocuousFox on January 24, 2003 5:51:13 PM]
cMyClass
cMyClassCollection
cMyClass* MyClassCollection[100];
//*********
cMyOther
cMyOtherCollection
cMyOther* MyOtherCollection[300];
short ClassID; //an index in MyClassCollection
//*********
//etc... I have many of these class/collection pairs
typedef std::list<cMyObjects*> MY_LIST;
class cMyObjectsCollection
MY_LIST MyList;