Woah, woah, woah. Stop right there New classes for every combination is over-complicating everything massively. It also kills the possibility of polymorphism, as a class can only extend one class.
Ok let’s start from the basics - what’s your database layout?
I’m assuming (hoping) it’d be something like:
[B][U]People[/U]
[/B]ID
Name
Address
Etc
[U]
Customers[/U]
Person ( = People.ID)
etc
[U][B]Members[/B][/U]
Person ( = Customers.ID)
etc
[U][B]Employees[/B][/U]
Person ( = People.ID)
etc
That way you could have something like:
interface iPerson{
public function getID();
public function getName();
public function getAddress();
public function setAddress($Address);
public function isEmployee();
public function isCustomer();
public function isMember();
public function getEmployee();
public function getCustomer();
public function getMember();
}
class Person implements iPerson{
protected $ID, $Name, $Address;
protected $Employee = null, $Customer = null, $Member = null;
public function getID(){
return $this->ID;
}
public function getName(){
return $this->Name;
}
public function getAddress(){
return $this->Address;
}
public function setAddress($Address){
$this->Address = $Address;
}
public function isEmployee(){
return !isNull($this->Employee);
}
public function isCustomer(){
return !isNull($this->Customer);
}
public function isMember(){
return !isNull($this->Member);
}
public function getEmployee(){
return $this->Employee;
}
public function getCustomer(){
return $this->Customer;
}
public function getMember(){
return $this->Member;
}
}
class PersonHolder implements iPerson{
protected $Person;
public function getID(){
return $this->Person->getID();
}
public function getName(){
return $this->Person->getName();
}
public function getAddress(){
return $this->Person->getAddress();
}
public function setAddress($Address){
return $this->Person->setAddress($Address);
}
public function isEmployee(){
return $this->Person->isEmployee();
}
public function isCustomer(){
return $this->Person->isCustomer();
}
public function isMember(){
return $this->Person->isMember();
}
public function getEmployee(){
return $this->Person->getEmployee();
}
public function getCustomer(){
return $this->Customer->getCustomer();
}
public function getMember(){
return $this->Member->getMember();
}
}
class Customer extends PersonHolder{
protected $SomethingCustomerRelated = null;
function __Construct(....){
$this->Person = $Person;
}
function getSomethingEmployeeRelated(){
return $SomethingCustomerRelated;
}
}
class Employee extends PersonHolder{
protected $SomethingEmployeeRelated = null;
function __Construct(....){
$this->Person = $Person;
}
function getSomethingEmployeeRelated(){
return $SomethingEmployeeRelated;
}
}
class Member extends PersonHolder{
protected $SomethingMemberRelated = null;
function __Construct(....){
$this->Person = $Person;
}
function getSomethingMemberRelated(){
return $SomethingMemberRelated;
}
}
By doing this, a customer, member and employee can all contain a person object which, once changed, will affect the customer, member and employee objects. It also means that all of them implement the iPerson interface, so passing a customer to a function which expects a person:
function assassinate(iPerson $Person){ ... }
You can assassinate (assuming your company is, in fact, an evil organisation) a customer, person or employee in the same way. The Person object also has access to the employee, member and customer objects, if they so exist, and has methods to see if they do or don’t exist.
There may be other ways of going about it, but that seems the most logical to me.