Skip to content

Doctors Test Driver

useDoctors.php - OOP in PHP (Demonstration): Complete Code Listing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
    require_once('Doctor.php');
    require_once('Surgeon.php');
    require_once('Dermatologist.php');
    require_once('Cardiologist.php');
    require_once('Neurosurgeon.php');

    echo '***** Doctor *****<br/>';
    $aDoctor = new Doctor();
    $aDoctor->setName("Larry");
    $aDoctor->drawBlood();

    echo '<br/>***** Surgeon *****<br/>';
    $aSurgeon = new Surgeon();
    $aSurgeon->setName("Homer");
    $aSurgeon->drawBlood(); // inherited from the base class Doctor
    $aSurgeon->cutPeopleOpen();

    echo '<br/>***** Dermatologist *****<br/>';
    $aDermatologist = new Dermatologist();
    $aDermatologist->setName("Sinefeld");
    $aDermatologist->drawBlood(); // inherited from the base class Doctor
    $aDermatologist->popPimples();

    echo '<br/>***** Cardiologist *****<br/>';
    $aCardiologist = new Cardiologist();
    $aCardiologist->setName('Kevorkian');
    $aCardiologist->drawBlood(); // overridden from the base class Doctor
    $aCardiologist->cutPeopleOpen(); // inherited from the base class Surgeon
    $aCardiologist->harvestHearts();

    echo '<br/>***** Neurosurgeon *****<br/>';
    $aNeurosurgeon = new Neurosurgeon();
    $aNeurosurgeon->setName('Frankenstein');
    $aNeurosurgeon->drawBlood(); // inherited from the base class Doctor
    $aNeurosurgeon->cutPeopleOpen(); // inherited from the base class Surgeon
    $aNeurosurgeon->removeSkull();

    echo '<br/>***** All Doctors to Draw Blood Stat!<br/>';
    $doctors = array($aDoctor, $aSurgeon, $aDermatologist, 
            $aCardiologist, $aNeurosurgeon);

    foreach ($doctors as $doctor)
    {
        $doctor->drawBlood();
    }