我正在創建Zend Framework中與數據訪問層分離的領域層。數據訪問層由兩個主要對象組成,一個是表格數據網關和一個行數據網關。按照比爾Karwin的答覆this earlier question我現在有下面的代碼爲我的域Person對象:如何設計域層對象來表示Zend框架中的多個對象和單個對象?
class Model_Row_Person
{
protected $_gateway;
public function __construct(Zend_Db_Table_Row $gateway)
{
$this->_gateway = $gateway;
}
public function login($userName, $password)
{
}
public function setPassword($password)
{
}
}
然而,這僅與單獨的行工作。我還需要創建一個可以表示整個表的域對象,並且(大概)可以用來遍歷表中的所有Person,並返回適當類型的人(admin,buyer等)對象以供使用。基本上,我想像如下:
class Model_Table_Person implements SeekableIterator, Countable, ArrayAccess
{
protected $_gateway;
public function __construct(Model_DbTable_Person $gateway)
{
$this->_gateway = $gateway;
}
public function current()
{
$current = $this->_gateway->fetchRow($this->_pointer);
return $this->_getUser($current);
}
private function _getUser(Zend_Db_Table_Row $current)
{
switch($current->userType)
{
case 'admin':
return new Model_Row_Administrator($current);
break;
case 'associate':
return new Model_Row_Associate($current);
break;
}
}
}
這是處理這個特定問題的好/壞方法?我應該對整體設計進行哪些改進或調整?
在此先感謝您的意見和批評。
順便說一句,我用這個練習來學習如何在新的NetBeans 6.5中編寫PHP代碼。它岩石! – 2008-12-17 01:34:39