0

I have a database table (mysql) representing the entity Employee in an enterprise like application. Surrogate keys are used throughout the database, so every Employee record has an auto incremented ID column identifying the Employee. I have modelled the Employee as a Business Object (BO) in php like this:

class Employee 
{
    public $id;    // surrogate key of database record
    public $firstName;
    public $user;
    public $posInCompany // associated EmployeePosition

    public function __construct($emplData)
    {
        $this->id = $emplData['id'];
        // ... init other properties
    }       
}

I am wondering if the $id property should be part of that class? Actually it represents the surrogate key from database and is thus storage-related. But I want the BOs to know nothing about the way they are stored/loaded (seperation of logic from persistence). The BOs hold the business logic for me and I want to work with them WITHOUT any coupling to type of storage (database etc.). With my above class layout I could never instantiate an Employee without giving an $id, so I guess this is not the correct way to implement a BO.

I want to work with DAO pattern to store/load Employee. Should I use the $id only within DAO concerns?

Further I am concerned about identifying an Employee object in my application later, which would work well with the surrogate $id. The $user property is also unique for every Employee in the database. So maybe I should use this property instead?

4

0 回答 0