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…


This content originally appeared on DEV Community and was authored by Ghulam Mujtaba

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.


This content originally appeared on DEV Community and was authored by Ghulam Mujtaba


Print Share Comment Cite Upload Translate Updates
APA

Ghulam Mujtaba | Sciencx (2024-07-25T12:02:28+00:00) Abstract classes in OOP. Retrieved from https://www.scien.cx/2024/07/25/abstract-classes-in-oop/

MLA
" » Abstract classes in OOP." Ghulam Mujtaba | Sciencx - Thursday July 25, 2024, https://www.scien.cx/2024/07/25/abstract-classes-in-oop/
HARVARD
Ghulam Mujtaba | Sciencx Thursday July 25, 2024 » Abstract classes in OOP., viewed ,<https://www.scien.cx/2024/07/25/abstract-classes-in-oop/>
VANCOUVER
Ghulam Mujtaba | Sciencx - » Abstract classes in OOP. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/25/abstract-classes-in-oop/
CHICAGO
" » Abstract classes in OOP." Ghulam Mujtaba | Sciencx - Accessed . https://www.scien.cx/2024/07/25/abstract-classes-in-oop/
IEEE
" » Abstract classes in OOP." Ghulam Mujtaba | Sciencx [Online]. Available: https://www.scien.cx/2024/07/25/abstract-classes-in-oop/. [Accessed: ]
rf:citation
» Abstract classes in OOP | Ghulam Mujtaba | Sciencx | https://www.scien.cx/2024/07/25/abstract-classes-in-oop/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.