Answers for "What is the purpose of an abstract?"

PHP
1

What is the purpose of an abstract?

abstract class AbstractDonater
{
    public function donateMinimum(): void
    {
        // this method can be complex
        $minimum = 10;
        $this->donate($minimum)
    }
    abstract protected function donate(int $money);
} 

class ConcreteDonaterOne 
{
    protected function donate(int $money)
    {
        $donateProvider = new PlayPal();
        $donateProvider->pay($money);
    }
}

class ConcreteDonaterTwo 
{
    protected function donate(int $money)
    {
        $donateProvider = new Scribe();
        $donateProvider->transfer($money);
    }
}
$donaters = [
    new ConcreteDonaterOne(),
    new ConcreteDonaterTwo(),

];

foreach ($donaters as $donater)
{
    $donater->donateMinimum();
}
Posted by: Guest on April-18-2021

Code answers related to "What is the purpose of an abstract?"

Browse Popular Code Answers by Language