June 2017
Intermediate to advanced
536 pages
9h 49m
English
The lazy initialization pattern is useful for addressing objects whose instantiation is likely to be resource-intense. The idea is to delay the actual resource intense operation until its result is actually required. The PDF generation is an example of a light to moderately resource-intense operation.
The following example demonstrates a possible lazy initialization pattern implementation based on PDF generation:
<?phpinterface PdfInterface{ public function generate();}class Pdf implements PdfInterface{ private $data; public function __construct($data) { $this->data = $data; // Imagine resource intensive pdf generation here sleep(3); } public function generate() { echo 'pdf: ' . $this->data; }}class ProxyPdf ...
Read now
Unlock full access