Answer the question
In order to leave comments, you need to log in
How to use Barbara Liskov's Substitution Principle in PHP?
PHP lacks Double Dispatching and method overloading (and will fail with an error in response to a different signature from the base class/interface). But somehow we need to solve the problem: let's say we have some classes that can be processed by different handlers:
interface IService
{
public function methodC();
}
class Service1 implements IService
{
public function methodA() {}
public function methodC() {}
}
class Service2 implements IService
{
public function methodB() {}
public function methodC() {}
}
interface IHandler
{
public function handle(IService $service);
}
class Handler1 implements IHandler
{
public function handle(IService $service) {}
}
class Handler2 implements IHandler
{
public function handle(IService $service) {}
}
Answer the question
In order to leave comments, you need to log in
PHP lacks Double Dispatching and method overloading
class Foo {
// ...
public function makeSomeStuff(Bar $bar)
{
$bar->doStuff($this->someData); // double dispatch!
}
}
class Foo {
public function foo() {}
}
class Bar extends Foo {
public function foo() {} // перегружен!
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question