-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
2,368 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace DesignPatterns\Behavioral\NullObjectPattern; | ||
|
||
/** | ||
* Class DaisyMae. | ||
*/ | ||
class DaisyMae implements NPC | ||
{ | ||
/** | ||
* @param int $price | ||
* @param int $count | ||
*/ | ||
public function buyTurnips(int $price, int $count) | ||
{ | ||
echo "[曹賣] 今天的價格是 1 棵 $price 鈴錢,要現在買嗎?"; | ||
} | ||
|
||
/** | ||
* @param int $price | ||
* @param int $count | ||
*/ | ||
public function sellTurnips(int $price, int $count) | ||
{ | ||
echo "[曹賣] 我是曹賣,你不能把大頭菜賣給我。"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace DesignPatterns\Behavioral\NullObjectPattern; | ||
|
||
/** | ||
* Class Mamekichi. | ||
*/ | ||
class Mamekichi implements NPC | ||
{ | ||
/** | ||
* @param int $price | ||
* @param int $count | ||
*/ | ||
public function buyTurnips(int $price, int $count) | ||
{ | ||
echo "[豆狸] 我是豆狸,我沒有在賣大頭菜狸。"; | ||
echo "[粒狸] 沒有在賣。"; | ||
} | ||
|
||
/** | ||
* @param int $price | ||
* @param int $count | ||
*/ | ||
public function sellTurnips(int $price, int $count) | ||
{ | ||
$total = $price * $count; | ||
echo "[豆狸] 現在的大頭菜價格是 1 棵 $price 鈴錢!"; | ||
echo "[粒狸] 鈴錢!"; | ||
echo "[豆狸] 好了!那麼,一共是 $total 鈴錢,確定要賣掉嗎?"; | ||
echo "[粒狸] 賣掉嗎?"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace DesignPatterns\Behavioral\NullObjectPattern; | ||
|
||
/** | ||
* Interface NPC. | ||
*/ | ||
interface NPC | ||
{ | ||
/** | ||
* @param int $price | ||
* @param int $count | ||
*/ | ||
public function buyTurnips(int $price, int $count); | ||
|
||
/** | ||
* @param int $price | ||
* @param int $count | ||
*/ | ||
public function sellTurnips(int $price, int $count); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace DesignPatterns\Behavioral\NullObjectPattern; | ||
|
||
/** | ||
* Class Player | ||
*/ | ||
class Player | ||
{ | ||
/** | ||
* @var NPC | ||
*/ | ||
protected NPC $npc; | ||
|
||
/** | ||
* | ||
* @param NPC $npc | ||
*/ | ||
public function __construct(NPC $npc) | ||
{ | ||
$this->setNPC($npc); | ||
} | ||
|
||
/** | ||
* @param NPC $npc | ||
*/ | ||
public function setNPC(NPC $npc) | ||
{ | ||
$this->npc = $npc; | ||
} | ||
|
||
/** | ||
* @param int $price | ||
* @param int $count | ||
*/ | ||
public function buy(int $price, int $count) | ||
{ | ||
$this->npc->buyTurnips($price, $count); | ||
} | ||
|
||
/** | ||
* @param int $price | ||
* @param int $count | ||
*/ | ||
public function sell(int $price, int $count) | ||
{ | ||
$this->npc->sellTurnips($price, $count); | ||
} | ||
} |
Oops, something went wrong.