|
Posted by Marcin Dobrucki on 08/12/05 15:35
I am writing an app where an "environment" contains a few managers which
arbitrate access to objets. The scenario is something like this:
class Env {
var $db;
var $manager_a;
var $manager_b;
function Env () {
// start pseudo code for db connection:
$this->db = open_connection();
// end pseudocode
$this->manager_a = new A(&this->db);
$this->manager_b = new B(&this->db);
}
}
class A {
var $db_ref;
function A ($ref) {
$this->db_ref = $ref;
}
}
class B {
var $db_ref;
function B ($ref) {
$this->db_ref = $ref;
}
}
This works, but now, I sometimes need to be able to access one manager
from within the other, in order to arbitrate access and so on. The way
I do it now is something like this:
class B {
var $db_ref;
var $manager_a_ref;
function B ($ref, $ref_A) {
$this->db_ref = $ref;
$this->manager_a_ref = $ref_A;
}
}
// and then in Env:
// $this->manager_b = new B(&$this->db, &$this->manager_a)
But the app is growing, and more managers are being added, so I am going
to be running into a problem of having to store a good deal of
references within each manager. So I was pondering if it'd be possible
to do something like this:
function Env () {
....
$this->manager_a = new A(&$this);
...
}
Allowing me to reference back (within some manager)
$this->ref->manager_other->... get what I want. I've recoded the above
example to try to do this, but it fails, and I am not sure if I got lost
in syntax or if this is complete bollocks. Any ideas? Any alternative
solutions?
/Marcin
Navigation:
[Reply to this message]
|