Circular Import problem...

BlitzMax Forums/BlitzMax Programming/Circular Import problem...

SofaKng(Posted 2007) [#1]
Let's say I have two very simple classes:

GameObject
and
GameObjectComponent

Each GameObject has a list of GameObjectComponents.

I'd like my GameObjectComponent to have a reference to the GameObject it currently "belongs" to.

If these two classes are stored in different files then I have a circular reference problem. (eg. GameObject needs to know about GameObjectComponent, and GameObjectComponent needs to know about GameObject)

What am I doing wrong? I really don't want to store these two classes in the same file...


Gabriel(Posted 2007) [#2]
Personally, I'd put them in a module.

If you don't want to do that, Include the files each type is in from a single source file.


H&K(Posted 2007) [#3]
I really don't want to store these two classes in the same file...
And I dont want to go to work tomorrow. But some things you have to do.


Brucey(Posted 2007) [#4]
One way is to create an Abstract Type that say you GameObjectComponent extends, the definition of which you store in another file.
Then, instead of your GameObject holding a reference to GameObjectComponent, it holds a reference to this Abstract Type instead.
Both your .bmx files would import this new file instead of each other.


Dreamora(Posted 2007) [#5]
Drop those ideas and use the package approach:

Include all BMX files that have classes that depend on each other into a single BMX file and import that one.

That way the package only has to be recompiled if one of the included is, otherwise Quick Build will not rebuild the package and you have very short recompilation times.