Это называется методом "тыка". В сложной взаимосвязи неизбежно будут ошибки (различные состояния).
class Example
{
public $property;
public function method()
{
if($this->property == 2){
$this->otherMethod();
}
}
public function otherMethod()
{
}
}
(new Example)->get();
Интерфейс подразумевает, что ты сразу знаешь, что нужно реализовать. К тому же класс может реализовывать несколько интерфейсов, но в определенный момент может потребоваться только знать, что имеется реализация конкретного интерфейса .
interface ExampleInterface{
public method();
public otherMethod();
}
interface OtherInterface{
}
class Example implements ExampleInterface, OtherInterface
{
public $property;
public function method()
{
if($this->property == 2){
$this->otherMethod();
}
}
public function otherMethod()
{
}
}
class SomeClass
{
public function __construct(ExampleInterface $example){
}
}
class OtherClass
{
public function __construct(OtherInterface $example){
}
}
$example = new Example();
$someClass = new SomeClass($example);
$otherClass = new OtherClass($example);
_____________
Mysql, Postgresql, Redis, Memcached, Unit Testing, CI, Kohana, Yii, Phalcon, Zend Framework, Joomla, Open Cart, Ymaps, VK Api