Sto ancora cercando di avvolgere la mia mente attorno a OOP. Tutti gli esempi seguenti funzionano, naturalmente, ma c'è uno (o forse un altro) che meglio esemplifica i concetti OOP?
/**
* For the following examples the Image class queries an image
* and associated info from a database, which is passed on
* instantiation via dependency injection.
*/
$image = new Image(new Db());
Esempio 1:
if ($image->setImageId($id, $size)) {
header('content-type: ' . $image->content_type);
header('content-length: ' . $image->length);
echo $image->getBytes();
}
Esempio 2:
if ($image_info = $image->getImageInfoByIdAndSize($id, $size)) {
header('content-type: ' . $image_info->content_type);
header('content-length: ' . $image_info->length);
echo $image->getImageBytesByIdAndSize($id, $size);
}
Esempio 3:
$image->setImageIdAndSize($id, $size);
if ($image_info = $image->getImageInfo()) {
header('content-type: ' . $image_info->content_type);
header('content-length: ' . $image_info->length);
echo $image->getImageBytes();
}