我知道 LSP 以及以下代码给出的原因:
PHP 致命错误:UnauthenticatedUser::executeCommand(UnauthenticatedCommand $c) 的声明必须与第 13 行 /tmp/test.php 中的 User::executeCommand(Command $c) 兼容
但是,我认为这两个接口Command
和UnauthenticatedCommand
是等效的(因为它们只是标记接口)。
鉴于这些事实,什么是干净的[1]方法可以使未经身份验证的用户无法执行除UnauthenticatedCommand
?
<?php
interface Command {
}
interface UnauthenticatedCommand extends Command {
}
interface User {
public function executeCommand(Command $c);
}
class UnauthenticatedUser implements User {
public function executeCommand(UnauthenticatedCommand $c) {
}
}
Run Code Online (Sandbox Code Playgroud)
[1]干净的意思是不使用自省,既不以编程方式也不以引擎的支持 ( instanceof
)。
归档时间: |
|
查看次数: |
159 次 |
最近记录: |