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 中国語 Web サイトの他の関連記事を参照してください。

ソース:dev.to
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!