我正在嘗試爲不同貨幣如Euro,Doller等實現Currency貨幣類。 我試圖創建一個抽象類並希望將Euro和Doller類從這個班。如何以更好的方式擴展這個抽象類
由於我是PHP新手,不知道這是否是更好的實現這種想法的方法。
abstract class Currency {
private $name;
private $symbol;
private $decimal;
private $decimal_point;
private $thousand_sep;
function __construct() {
}
function setName($name) {
$this->name = $name;
}
function getName() {
return $this->name;
}
function setSymbol($symbol) {
$this->symbol = $symbol;
}
function getSymbol() {
return $symbol;
}
function setDecimal($decimal) {
$this->decimal = $decimal;
}
function getDecimal() {
return $this->decimal;
}
function setDecimalPoint($decimal_point) {
$this->decimal_point = $decimal_point;
}
function getDecimalPoint() {
$this->decimal_point;
}
function setThousandSeprator($thousand_sep) {
$this->thousand_sep = $thousand_sep;
}
function getThousandSeprator() {
return $this->thousand_sep;
}
function display() {
return $this->symbol . number_format($this->amount, $this->decimal, $this->decimal_point, $this->thousand_sep);
}
}
只是一個提示:http://php.net/manual/en/class.numberformatter.php - 它是從國際圖書館這是開源的,你可以看看。 – hakre