MelodyMaker
Programmer
Sorry if I bother you with this, but I'm a OOP newbie and I would like to know your opinion about that.
I'm developing a site which requires registration and where users can upload their fotos. The question is this:
I created a user class
Code:
class User{
private $username;
private $email;
private $country;
??? private $photos= Array();???
...
function __construct($idUser) //here I load the details about the user;
}
Now, every user can upload at most 12 photos, which can have a small caption.
So, the question:
1) Do I need a "Photo" Class? (the encapsulation principle tells me so)
In this case what is the best way to associate this class to the user class? By storing the photo objects in an array property of the user class? And where should I put the method "loadPhotos"? In the user or in the photo class?
Code:
class Photo(){
private $url;
private $caption;
function __construct($IDPhoto){
.... here another select on the same table, mmm
}
}
...but if I do this, there will be two SELECT : One to get the user's ID photo and the other to retrieve photo's data. Or I'm wrong..?
2) Storing all the data about photos in an array (as a property) and forget about Photo class?
I'm a bit confused, sorry.
Thank you very much in advance.
Davide
I'm developing a site which requires registration and where users can upload their fotos. The question is this:
I created a user class
Code:
class User{
private $username;
private $email;
private $country;
??? private $photos= Array();???
...
function __construct($idUser) //here I load the details about the user;
}
Now, every user can upload at most 12 photos, which can have a small caption.
So, the question:
1) Do I need a "Photo" Class? (the encapsulation principle tells me so)
In this case what is the best way to associate this class to the user class? By storing the photo objects in an array property of the user class? And where should I put the method "loadPhotos"? In the user or in the photo class?
Code:
class Photo(){
private $url;
private $caption;
function __construct($IDPhoto){
.... here another select on the same table, mmm
}
}
...but if I do this, there will be two SELECT : One to get the user's ID photo and the other to retrieve photo's data. Or I'm wrong..?
2) Storing all the data about photos in an array (as a property) and forget about Photo class?
I'm a bit confused, sorry.
Thank you very much in advance.
Davide