OOP 中的抽象类

WBOY
发布: 2024-07-26 03:17:03
原创
646 人浏览过

Abstract classes in OOP

Abstract classes in PHP are classes that cannot be instantiated on their own and are designed to be inherited by other classes. They can contain both abstract and concrete methods.

Abstract classes are defined using the abstract keyword, and any class that contains at least one abstract method must be declared as an abstract class.

Characteristics

  1. Cannot be instantiated directly
  2. Must be inherited by another class
  3. Can contain both abstract and concrete methods
  4. Abstract methods must be implemented by child classes
  5. Concrete methods can be used by child classes without implementation
<?php

abstract class AchivementType
{
    public function name(){
        $class = (new ReflectionClass($this))->getShortName();
        return trim(preg_replace('/[A-Z]/','$0', $class));
    }
    public function icon()
    {
        return strtolower(str_replace('','-', $this->name())).'.png';
    }
    abstract public function qualifier($user);
}
登录后复制

I hope that you have clearly understood the concept of abstract classes.

以上是OOP 中的抽象类的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:dev.to
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!