[英]Declare an Abstract class in php
我有2个类-A和B都应使用.ini或.php的配置文件。 两者都有方法调用post从diffrent api获取smth的最佳设计方法是什么?
我是否需要使用abstact将配置放入他的构造函数中。 ? 我只需调用$ this-> config就能得到配置。
例如:
abstract class parent
{
constructor()
{
$this->config = "get file";
}
}
class a extends parent {
...
how to use $this->conifg ?
}
多谢
只需在您的父类中定义一个函数,即可返回您的配置:
abstract class parent
{
private config;
public function __construct()
{
$this->config = "get file";
}
public function getConfig(){
return $this->config;
}
}
class a extends parent
{
private config;
public function __construct(){
$this->config = parent::getConfig();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.