Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Design Domain Layer Objects to Represent Multiple Objects & Single Object in Zend Framework?
    primarykey
    data
    text
    <p>I'm working on creating a domain layer in Zend Framework that is separate from the data access layer. The Data Access Layer is composed to two main objects, a Table Data Gateway and a Row Data Gateway. As per Bill Karwin's reply to <a href="https://stackoverflow.com/questions/373054/how-to-properly-create-domain-using-zend-framework">this earlier question</a> I now have the following code for my domain Person object:</p> <pre><code>class Model_Row_Person { protected $_gateway; public function __construct(Zend_Db_Table_Row $gateway) { $this-&gt;_gateway = $gateway; } public function login($userName, $password) { } public function setPassword($password) { } } </code></pre> <p>However, this only works with an individual row. I also need to create a domain object that can represent the entire table and (presumably) can be used to iterate through all of the Person's in the table and return the appropriate type of person (admin, buyer, etc) object for use. Basically, I envision something like the following:</p> <pre><code>class Model_Table_Person implements SeekableIterator, Countable, ArrayAccess { protected $_gateway; public function __construct(Model_DbTable_Person $gateway) { $this-&gt;_gateway = $gateway; } public function current() { $current = $this-&gt;_gateway-&gt;fetchRow($this-&gt;_pointer); return $this-&gt;_getUser($current); } private function _getUser(Zend_Db_Table_Row $current) { switch($current-&gt;userType) { case 'admin': return new Model_Row_Administrator($current); break; case 'associate': return new Model_Row_Associate($current); break; } } } </code></pre> <p>Is this is good/bad way to handle this particular problem? What improvements or adjustments should I make to the overall design? </p> <p>Thanks in advance for your comments and criticisms.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload