Answer the question
In order to leave comments, you need to log in
How to arrange calling methods one by one?
Hello! I am implementing a class that has one public method and the rest are hidden. Below is an example class structure. That is, in it, the public method calls the private methods one by one in a chain, but can also stop on any of the methods. Is this approach normal or is there a more elegant solution for such logic? Tell me please.
class Test
{
public function start()
{
try {
// do something...
return $this->one();
} catch (Throwable $exception) {
// do something...
}
return false;
}
private function one()
{
try {
// do something...
return $this->two();
} catch (Throwable $exception) {
// do something...
}
return false;
}
private function two()
{
try {
// do something...
return $this->three();
} catch (Throwable $exception) {
// do something...
}
return false;
}
private function three()
{
try {
// do something...
return true;
} catch (Throwable $exception) {
// do something...
}
return false;
}
}
$test = new Test();
$result = $test->start();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question