class A
{
_construct( B $class = null)
{
...
}
interface D {
public function execute();
}
class B implements D {
public function execute() {
return "This is B";
}
}
class C implements D {
public function execute() {
return "This is C";
}
}
class A {
public function __construct(D $class = null) {
if (!is_null($class)) {
echo $class->execute();
}
}
}
new A();
new A(new B());
new A(new C());