データアクセス層とは別のドメイン層をZendFrameworkで作成しています。データアクセス層は、テーブルデータゲートウェイと行データゲートウェイの2つの主要なオブジェクトで構成されています。この以前の質問に対するBillKarwinの回答によると、ドメインのPersonオブジェクトに次のコードがあります。
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を反復処理して、使用する適切なタイプの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;
}
}
}
これは、この特定の問題を処理するための良い/悪い方法ですか?デザイン全体にどのような改善や調整を加える必要がありますか?
コメントや批判をよろしくお願いします。