정확하게 이해한다면, 당신은 일반적인 작업을 수행하기를 원할 것입니다. 다른 유형의 개체 집합?
PHP에서 그렇게하려면 일반적인 작업을 정의하는 인터페이스를 작성한 다음 원래의 오브젝트를 래핑하고 인터페이스를 구현하는 프록시 클래스를 작성해야합니다. 예를 들어
, 당신은 이러한 클래스가있는 경우 :이 같은 인터페이스와 두 개의 프록시 클래스 쓸 수
class User {
public function getId() {
// Return some id
}
// Other user-specific stuff here
}
class Event {
public function getId() {
// Return some id
}
// Other user-specific stuff here
}
:
interface FacebookObject {
public function getId();
}
class UserProxy implements FacebookObject {
function __construct($user) {
$this->user = $user;
}
function getId() {
return $this->user->getId();
}
}
class EventProxy implements FacebookObject {
function __construct($event) {
$this->event = $event;
}
function getId() {
return $this->event->getId();
}
}
을 그리고 당신은 FacebookObject에서 작동 코드를 작성할 수 있습니다 프록시 :
function getFacebookId(FacebookObject $obj) {
return $obj->getId();
}
도움 주셔서 감사합니다 ... – Donald