PHP 5引入了“类型提示”,它使函数和方法能够声明“类型化”参数(对象).对于大多数情况,端口示例应该不是一项大任务,例如从Java到PHP 5.
原文链接:https://www.f2er.com/php/136581.html一个非常简单的例子:
interface MyClient { public function doSomething(); public function doSomethingElse(); } class MyHighLevelObject { private $client; public __construct(MyClient $client) { $this->client = $client; } public function getStuffDone() { if ( any_self_state_check_or_whatever ) $client->doSomething(); else $client->doSomethingElse(); } // ... } class MyDIP implements MyClient { public function doSomething() { // ... } public function doSomethingElse() { // ... } }