Answer the question
In order to leave comments, you need to log in
What is the best way to implement setting the execution order of methods?
There are classes ModuleA, ModuleB, ModuleC, ... . Each with its own set of methods:
abstract class AbstractModule { /* ... */ }
class ModuleA extends AbstractModule
{
public function a1() { /* ... */ }
}
class ModuleB extends AbstractModule
{
public function b1() { /* ... */ }
public function b2() { /* ... */ }
}
class ModuleC extends AbstractModule
{
public function c1() { /* ... */ }
public function c2() { /* ... */ }
public function c3() { /* ... */ }
}
class Boss
{
/** @var AbstractModule[] **/
protected $_modules;
public function __construct(array $modules)
{
$this->_modules = $modules;
}
/**
* Последовательно запускает выполнение всех методы всех модулей с соблюдением условий.
*/
public function process()
{
// ...
}
}
Answer the question
In order to leave comments, you need to log in
In Module* add a public method that returns the rules. In process, for each loaded module, call such a method, and then form a launch sequence. In fact, although Boss does not know these rules, in the course of calling process, he essentially learns them. As a result, Boss does know the sequence, just indirectly.
I think that it is necessary to set the priority of methods inside the class and the priority of classes inside the heir, then before cyclic execution - sort by this priority.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question