PHP 디자인 모드 의 장식 모드
1846 단어 디자인 모드Php 디자인 모드장식 모드
wealthfactor;
}
}
//
class DiamondPlains extends Plains{
function getWealthFactor(){
return parent::getWealthFactor()+2;
}
}
//
class PollutedPlains extends Plains{
function getWealthFactor(){
return parent::getWealthFactor()-4;
}
}
// ,
질문:
오염 되 고 다이아몬드 가 함 유 된 땅 이 나타 나 면 그 부의 가 치 를 계산 해 야 한다. 그러면 우 리 는 여러 가지 종 류 를 만들어 야 하 는가?정 답: 필요 없습니다. 우 리 는 장식 모델 을 이용 하여 기 존의 독립 류 를 조합 하여 하나의 조합 류 가 되 어 부의 가 치 를 계산 하 는 방법 을 약간 바 꿀 수 있 습 니 다.
wealthfactor;
}
}
//
class DiamondPlains extends Plains{
protected $tile;
function __construct(Tile $tile){
$this->tile=$tile;
}
function getWealthFactor(){
return parent::getWealthFactor()+2+$this->tile->getWealthFactor();
}
}
//
class PollutedPlains extends Plains{
protected $tile;
function __construct(Tile $tile){
$this->tile=$tile;
}
function getWealthFactor(){
return parent::getWealthFactor()-4+$this->tile->getWealthFactor();
}
}
//
class PurePlains extends Plains{
protected $tile;
function __construct(Tile $tile){
$this->tile=$tile;
}
function getWealthFactor(){
return parent::getWealthFactor()+4+$this->tile->getWealthFactor();
}
}
//
$tile=new DiamondPlains(new PollutedPlains(new PurePlains()));
echo $tile->getWealthFactor();
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
디자인 모델 의 공장 모델, 단일 모델자바 는 23 가지 디자인 모델 (프로 그래 밍 사상/프로 그래 밍 방식) 이 있 습 니 다. 공장 모드 하나의 공장 류 를 만들어 같은 인 터 페 이 스 를 실현 한 일부 종 류 를 인 스 턴 스 로 만 드 는 것...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.