Suggestions on Passing References best practice

Hi,

I am looking for best practices when it comes to passing a reference to the last element on a chain of classes.

For example, lest say I have the following setup:

  • testApp
  • Flock
  • vector of Boids
  • Fish

testApp creates a Flock instance, Flock creates a bunch of Boids and Boids create an instance of Fish

I want to load all the fish texture images in testApp, and then pass a reference to all the images to the Fish objects

So a couple of questions:
1- Which method should I use to store the images?

A- vector * images;
B- vector <ofImage*> images;

2- Is there a shortcut to get the images vector from testApp to the Fish class directly? or do I have to create an pointer to images in Flock, Boid, Fish, so testApp pass a reference of images to Flock, Flock pass to Boids, Boids pass to Fish?

Any help will be much appreciated

PS. I dont want to abuse of your kindness but I also need help here http://forum.openframeworks.cc/t/vertex-array-texture-help/4120/0 its driving me crazy :roll:

Cheers
rS

Here is how I did it at the end:

In testApp I declare: vector images;
in the other classes I declare: vector * images
so I testApp when I create a new Flock class I do: flock.images = &images; and so on

It is working and is very easy for me to update and use the images as I please, if there is an easier/more efficient way of doing this, I will be glad to know, been new to all this referencing stuff makes me a bit unconfident of my implementations

Cheers
rS

Hey Nardove,

To me that looks like a nice and flexible solution. I always try to keep my classes as “stupid” as possible, there is no need to let them know too much detailed info, a reference is more then enough. This makes your classes re-usable for other projects too!

I do this with the motion too btw! my Boid.update() function will be really simple (dir+= velocity only). The Boid class wil have a lot of public vars (velocity,acceleration etc.) and they will be set by the flock class before the update is called.

cheers,

Joris