Posted on 12/12/2008 at 07:49 PM
I have moved the code for the example application that will accompany my book to google code.
It’s still at very early stage but I am slowly getting there! Feel free to submit code reviews, comments etc. I will hopefully be including some install instructions soon as well…
Storefront Example Application
Hi Keith,
Why did you decide to expose the underlying Zend_Db_Table_Row objects to your controllers from your model?
i.e. given that you’ve decided to use a “has a” relationship between Storefront_User and Storefront_Resource_User, why does Storefront_User::getUsers return a Zend_Db_Table_Rowset containing Storefront_Resource_User_Item objects? Surely this ties you to the Zend_Db underlying implementation?
I’m currently playing with something similar (though less abstracted, I suspect as I don’t use “resources) and I’m returning lists of ValueObjects but this kind of negates the point of using Zend_Db_Table at all.
Regards,
Rob…
Posted by
Rob... on 13/12/2008 at 08:56 AM
This design is a bit of a compromise really, the design I first started on used the Repository pattern. I was using Zend_Db_Table’s row rowClass to call a factory that created domain entities that had-a row object, it came unstuck a bit with relationships but I really went back to simplify for the purpose of the book.
The current design simply tries to abstract the table/rows enough to enable easy unit testing. When I return a rowset/row to my controller I would not call any db specific methods only the ones defined in the interface, such as in the product row which has getImages() etc.
I sort of came to the conclusion that Zend_Db_Table* is probably not the best tool to be trying to use when looking at implementing a domain model. I think that it would be much easier using an active record tool such as doctrine and then using a repository built upon that. Hopefully at work I will be doing this soon so should be able to post my experiences. Reading POEAA it does mention using the Table Module + Data Mapper to achieve a domain model, but sadly with no example, again when I get time I want to go over this again!
If I am understanding correctly, you are right to say that it is pointless to be returning valueObjects, the idea of a domain model means that all your business logic should be in those objects (Entities), though of course you do have Value Objects but these have no identity.
Hopefully I will get some time after I finish more of my book to have a look at getting a few proposals together that would help people get around some of these issues. Maybe a repository or data mapper for Zend_Db_table would be cool or maybe wait for 5.3 and use active record or maybe something else....
I have noticed a lot of talk on the lists about model design, it would be good maybe a some point to get some guys together to either write components or simply a really good lot of documentation that provides solutions form these problems.
Thanks for your comments, I didn’t think anyone read my blog hehe
Posted by [MuTe] on 13/12/2008 at 07:07 PM
Yeah,
It’s an interesting problem. I’m not sure there is a one size fits all either.
I’ve just blogged my latest thinking at http://akrabat.com/2008/12/13/on-models-in-a-zend-framework-application/
Regards,
Rob…
Posted by
Rob... on 13/12/2008 at 07:45 PM
Look at Matthew Weier O’Phinney paste bin application. Especially on spindle models http://github.com/weierophinney/pastebin/tree/master/application/modules/spindle/models .
Posted by
Power Man on 22/12/2008 at 12:02 AM