Design patterns Adapter Adapter Pattern (PHP)

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

A real world example using a scientific experiment where certain routines are performed on different types of tissue. The class contains two functions by default to get the tissue or routine separately. In a later version we have then adapted it using a new class to add a function that gets both. This means we have not edited the original code and therefore do not run any risk of breaking our existing class (and no retesting).

class Experiment {
    private $routine;
    private $tissue;
    function __construct($routine_in, $tissue_in) {
        $this->routine = $routine_in;
        $this->tissue  = $tissue_in;
    }
    function getRoutine() {
        return $this->routine;
    }
    function getTissue() {
        return $this->tissue;
    }
}

class ExperimentAdapter {
    private $experiment;
    function __construct(Experiment $experiment_in) {
        $this->experiment = $experiment_in;
    }
    function getRoutineAndTissue() {
        return $this->experiment->getTissue().' ('. $this->experiment->getRoutine().')';
    }
}


Got any Design patterns Question?