Tanımı şimdi ben size bir örnek vermek için çalışacağız, yukarıda söz edilir:
"abstract" ensures that you follow a specific logic, e.g. a ticket's material is ALWAYS "paper", or a creditcare must always have a "code".
This is important if you work in a big company which has strict standardisation or if you want to 'force' your developers to follow a specific structure, so their code won't end up in a mess.
abstract class ticket{
public function material()
{
return 'Paper';
}
}
abstract class creditcard{
public function material()
{
return 'Plastic';
}
abstract function setCode(); // the ";" semicolon is important otherwise it will cause an error
}
class key extends ticket{
public function getMaterial()
{
return parent::material();
}
}
class anotherKey extends creditcard{
public function setCode($code)
{
$this->code = $code;
}
}
Biz "setCode" yöntemini tanımlamak yoksa ayrıştırıcı "new anotherKey
" bir hata döndürecektir