简体   繁体   中英

When implementing an interface or extending an abstract class should you reference the abstract / interface or the implementation?

I have an abstract class that contains my database methods: abstractDatabase

I extended this class with: Database

When referring to this in another class, should I use abstractDatabase or Database ?

class Config
{
    public function setDatabase(\abstractDatabase $database) {
        $this->db=$database;
        return $this
}

or should it be written as:

class Config
{
    public function setDatabase(\Database $database) {
        $this->db = $database;
        return $this;
}

Also, when defining my abstract class, should I reference abstractClass or just Class

abstract class Database
{
    abstract function __construct(\abstractConfig $config);
}

or

abstract class Database
{
    abstract function __construct(\Config $config);
}

Same question regards implementing interfaces.

I have an abstract class that contains my database methods: abstractDatabase

I extended this class with: Database

When referring to this in another class, should I use abstractDatabase or Database ?

class Config
{
    public function setDatabase(\abstractDatabase $database) {
        $this->db=$database;
        return $this
}

or should it be written as:

class Config
{
    public function setDatabase(\Database $database) {
        $this->db = $database;
        return $this;
}

Also, when defining my abstract class, should I reference abstractClass or just Class

abstract class Database
{
    abstract function __construct(\abstractConfig $config);
}

or

abstract class Database
{
    abstract function __construct(\Config $config);
}

Same question regards implementing interfaces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM