php - Separate base class(template) and derive classes (data).? -
general
require('fpdf.php'); $pdf=new fpdf(); $pdf->addpage(); $pdf->setfont('arial','b',16); $pdf->cell(40,10,'hello world!'); $pdf->output();
i want separate 2 class (base , child(child data) )
base class (present template of output )
require('fpdf.php'); class base{ //todo function def(){ $pdf=new fpdf(); $pdf->addpage(); // page header in here // ->do in derived class(leave derived data ) // page footer in here $pdf->output(); } }
child class (manipulate data )
class child extends base{ //todo function def(){ $pdf->cell(40,10,'hello world!'); } }
when call use child class out pdf file
$obj_pdf = new child(); $obj_pdf->def();
how should implement it? or not possible this?
what want accomplish here wrapper pattern. don't know if right solution problem. inheritance meant add complexity in child classes, not extending functions in parent.
but wrapper try like:
class base{ //todo function def(){ require('fpdf.php'); $pdf=new fpdf(); $pdf->addpage(); // page header in here // ->do in derived class(leave derived data ) $child = new child(); $pdf = $child->def($pdf); // page footer in here $pdf->output(); } }
call with:
$obj_pdf = new base(); $obj_pdf->def();
Comments
Post a Comment