我正在尝试为不同货币如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