Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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();
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #What #purpose
ADD COMMENT
Topic
Name
5+3 =