PHP bir arabirim tanımlamak ve bu arabirim bir örneğini oluşturan bir fabrika sınıfı, ben sadece yatan beton sınıfı arayüzünü kullanmak değil, istemci kod zorlamak herhangi bir yolu var mı? Benim anlayış, müşterilerine gerçekten de altta yatan sınıfındaki herhangi bir kamu işlevleri / alanları kullanmak mümkün.
İşte bir örnek:
<?php
interface IMyInterface
{
public function doSomething();
}
?>
<?php
class ConcreteImplOfMyInterface implements IMyInterface
{
const NotPartOfInterface = 'youcantseeme';
public function doSomething()
{
}
}
?>
<?php
class MyInterfaceFactory
{
public static function createMyInterface()
{
return new ConcreteImplOfMyInterface();
}
}
?>
<?php
function client()
{
$myInterface = MyInterfaceFactory::createMyInterface();
return $myInterface::NotPartOfInterface;
}
?>