mercredi 3 avril 2019

Is double or mutual composition a bad practice in PHP?

I am coding some application and I wonder if is a bad practice to do double or mutual composition between two classes.

I have some code like this:

class A {}
class B {}

$a = new A;
$b = new B;

$a->setBInstance($b);
$b->setAInstance($a);

Off course I know I'll have some semantic problems if I'll try to get some instance indiscriminately as follow:

$a->getB()->getA() ...

But I really need double composition.

Aucun commentaire:

Enregistrer un commentaire