I have a user class comprised of the code below. It has functions to insert a user, update a user, delete a user, look up a user, and search for users. What I'm wondering is if I this class would pass the Single Responsibility Principle as stated here (http://en.wikipedia.org/wiki/Single_responsibility_principle).
class user{
$first_name = "";
$last_name = "";
$physical_address1 = "";
$physical_address2 = "";
$physical_city = "";
$physical_state = "";
$physical_zip = "";
$mailing_address1 = "";
$mailing_address2 = "";
$mailing_city = "";
$mailing_state = "";
$mailing_zip = "";
function __construct($array){
if(!isset($array['first_name']) && !empty($array['first_name'])){
$this->first_name = "";
}
if(!isset($array['last_name']) && !empty($array['last_name'])){
$this->last_name = "";
}
if(!isset($array['physical_address1']) && !empty($array['physical_address1'])){
$this->set_physicalAddress(array(
"address_1"=>$array['physical_address1'],
"address_2=>$array['physical_address2']",
"city"=>$array['physical_city'],
"state"=>$array['physical_state'],
"zip"=>$array['physical_zip']
));
}
if(!isset($array['mailing_address1']) && !empty($array['mailing_address1'])){
$this->set_mailingAddress(array(
"address_1"=>$array['mailing_address1'],
"address_2=>$array['mailing_address2']",
"city"=>$array['mailing_city'],
"state"=>$array['mailing_state'],
"zip"=>$array['mailing_zip']
));
}
}
function set_physicalAddress($array){}
function get_physicalAddress(){}
function set_mailingAddress($array){}
function get_mailingAddress(){}
static function insert($array){}
static function update($array){}
static function delete($int){}
static function lookup($array){}
static function search($array){}
}
$obj = new user(array(
"first_name"=>"John",
"last_name"=>"Smith"
));
The purpose of having the constructor parameter value be an array is that I feed it only the values I want without having to deal with errors caused by not setting a parameter. Instead of setting the parameters to null it's easier to just not put them in the array.