В общем, есть три листинга, какой будет правильнее использовать в контексте поставленной задачи
Листиг 1
Листиг 2
Листиг 3
Листиг 1
PHP:
<?php
interface client {
public function add();
}
class client_base {
protected function save() {
// some code here
}
}
class client_persone extends client_base implements client {
public function add() {
// some code here
$this->save();
}
}
class client_company extends client_base implements client {
public function add() {
// some code here
$this->save();
}
}
?>
PHP:
<?php
abstract class client_base {
/**
* В абстрактном классе мы можем декларировать это
* @var bar
*/
protected $foo;
/**
* phpDOC hear
*/
protected function save() {
// some code here
}
/**
* В отличии от interface, в абстактом классе мы можем декларировать protected
*/
abstract protected function del();
}
class client_persone extends client_base {
public function add() {
// some code here
$this->save();
}
protected function del() {
// some code here
}
}
class client_company extends client_base {
public function add() {
// some code here
$this->save();
}
protected function del() {
// some code here
}
}
?>
PHP:
<?php
interface client {
public function add();
}
class client_persone implements client {
public function add() {
// some code here
$this->save();
}
protected function save() {
// some code here
}
}
class client_company extends client_persone implements client {
public function add() {
// some code here
$this->save();
}
}
?>