Jump to content

JarWithLid

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

JarWithLid's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Do you have a recomendation for a book on said design patterns? Thanks, Adam
  2. Here is my question: Say I have the objects below. Supose an ImageSet object is created, named $fauxSet, that contains 200 images. When you call $fauxSet->getImages() you are creating an array of 200 Image objects. Awesome. So nice. But is that considered horrible as it will hit the mySql server with 201 queries when you could get the same info, without creating the objects, with just 1? The latter would have drawbacks: Sacraficing code reuse principles of OOP, no longer having the ability to use someFunction() on those objects, etc. Opinions / Suggestoins? [code] class Image {   public $id;   public $setid;   public $name;   public $description;   public $file;   public function __construct($id) {     // Query images table, fill member variables   }   public function someFunction () {     // Some function you can perform with this object   } } class ImageSet {   public $id;   public $name;   public $description;   public function __construct($id) {     // Query image_sets table, fill member variables   }   // This function returns an array of the Image objects in this ImageSet   public function getImages () {     $imgAr = array(); // What we will return     $images = new mySql("SELECT id FROM images WHERE setid = $this->id"); // Gets all of the image ids from database         while ($images->nextRow()) {       $imgAr[] = new Image($images->id);     }     return $imgAr;   } } [/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.