i've been facing a common situation at work that has happened quite often when handling objects.

The situation goes like this:

You have to realted classes A and B, class A has an instances of class B. Now, imagine that we want to call methodB of class B, but we only have access to an intance of class A. What's the best approach to this situation and why:

Ainstances->getClassBInstance()->methodB();

or

Ainstances->methodB()

where methodB is implemented as follows:

function methodB()
{
  return self.getClassBInstance()->methodB()
}

没有正确的解决方案

许可以下: CC-BY-SA归因
scroll top