mercredi 24 mai 2017

Which design pattern use when different libraries to create a Spreadsheet?

In my controller class I just want to use only one spreadsheet class to handle all the functions related to spreadsheet creation, save, load, write etc.

Currently I'm using one open source library phpspreadsheet to create a spreadsheet, if later I want to change that to another library of spreadsheet creation, I don't want to change much on the controller class, instead, I can create another class for this library, like Spreadsheetlib2. So which design pattern is better to use here? "Bridge" or Adapter?

// Bridge Pattern what I'm trying now.

interface SpreadsheetInterface {

    public function create();

    public function write();

}


class Spreadsheet extends AbstractSpreadsheet {

    public function create() {

    }
}



class PhpSpreadsheet implements SpreadsheetInterface {

    public function create() {

    }
}


abstract class AbstractSpreadsheet {

    protected $spreadsheet;

    protected function __construct(SpreadsheetInterface $spreadsheet) {
        $this->spreadsheet = $spreadsheet;
    }
}

Aucun commentaire:

Enregistrer un commentaire