EDIT 3: Attempt at re asking the question.
class Config {
protected $a;
protected $b;
public doStuff();
public getA();
}
CASE 1
class Connection {
protected $config;
public function __construct(){
$this->config = new Config();
}
public function getConfig(){
return $this->config;
}
}
$c = new connection();
$c->getConfig()->doStuff();
$otherClass->setA($c->getConfig()->getA());
CASE FACTORY/CONTROLLER
$config = new Config();
$config->doStuff();
$a = $config->getA();
$otherClass->setA($a);
Whats the difference ?
OLD QUESTION FOLLOWING, NOT CLEAR
So I was reading about composition vs inheritance even though it's been 8 years Im programming because you know modelling a program doesn't have simple clean cut answers such as a plane vs a biplane and an engine and this simple interrogation came over my mind.
A biplane IS a plane and a plane HAS an engine and HAS seats and HAS "most likely" windows.
The plane class has an engine, seats and windows. Classical case of composition. In other words, the plan contains 3 sub objects.
Now, what if, we had a factory of planes. This factory technically would assemble the plane meaning it would have a plane, an engine and seats. Now think about the principle of a controller which acts as an intermediary between the model and the view. It could almost be seen as a factory of different objects needed(the models) needed to create the view.
My question is, could I simply create a controller/factory which contains the seats,plane,windows object without the plane itself having those 3 previous objects embedded in the plane object ?
So, basically "decoupling" the "HAS logic" into one big factory/controller. What do you think ?
Edit: My question doesn't make sense in this specific example because the plane sub object actually return objects and dont do stuff. Imagine if those sub objects were only doing stuff and returning void