在 php 中声明摘要 class
Declare an Abstract class in php
我有 2 个 类 - A 和 B
两者都应该使用 .ini 或 .php 中的配置文件。
并且都有方法调用 post 从不同的 api 获取 smth
什么是最好的设计方式?
我是否需要使用抽象并将配置放入他的构造函数中。 ?
我将能够通过调用 $this->config?
来获取配置
例如:
abstract class parent
{
constructor()
{
$this->config = "get file";
}
}
class a extends parent {
...
how to use $this->conifg ?
}
非常感谢
只需在您的父级 class 中定义一个函数,即 returns 您的配置:
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();
}
}
我有 2 个 类 - A 和 B 两者都应该使用 .ini 或 .php 中的配置文件。 并且都有方法调用 post 从不同的 api 获取 smth 什么是最好的设计方式?
我是否需要使用抽象并将配置放入他的构造函数中。 ? 我将能够通过调用 $this->config?
来获取配置例如:
abstract class parent
{
constructor()
{
$this->config = "get file";
}
}
class a extends parent {
...
how to use $this->conifg ?
}
非常感谢
只需在您的父级 class 中定义一个函数,即 returns 您的配置:
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();
}
}