<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>rvdavid: A Web Developer&#039;s Blog &#187; service layer</title> <atom:link href="http://www.rvdavid.net/tag/service-layer/feed/" rel="self" type="application/rss+xml" /><link>http://www.rvdavid.net</link> <description>A periodical blog of experiences from the angle of an autodidactic, paranoid and narcissistic web developer...</description> <lastBuildDate>Wed, 01 Sep 2010 12:47:15 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator><meta
xmlns="http://www.w3.org/1999/xhtml" name="robots" content="noindex,follow" /> <item><title>My Zend Framework Model Layer: Part Service, Part ORM</title><link>http://www.rvdavid.net/my-zend-framework-model-layer-part-service-part-orm/</link> <comments>http://www.rvdavid.net/my-zend-framework-model-layer-part-service-part-orm/#comments</comments> <pubDate>Tue, 19 Jan 2010 17:38:29 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[Zend Framework]]></category> <category><![CDATA[mvc]]></category> <category><![CDATA[php]]></category> <category><![CDATA[service layer]]></category> <category><![CDATA[Web Development]]></category><guid
isPermaLink="false">http://www.rvdavid.net/?p=307</guid> <description><![CDATA[The Model Layer of the MVC triad: I&#8217;ve been thinking this over for the past few months since using the Doctrine ORM and I think I&#8217;ve finally made some progress to get this issue licked. In the past, I&#8217;ve agonised over this issue and blogged about my progress. Some weeks or days later I tried to probe the [...]]]></description> <content:encoded><![CDATA[<div
class="adsense adsense-leadin" style="float:right;margin: 12px;"><script type="text/javascript">google_ad_client = "pub-3968550303568935";
/* 250x250, created 07/06/10 */
google_ad_slot = "3782770990";
google_ad_width = 250;
google_ad_height = 250;</script> <script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div><p>The Model Layer of the MVC triad: I&#8217;ve been thinking this over for the past few months since using the Doctrine ORM and I think I&#8217;ve finally made some progress to get this issue licked. In the past, I&#8217;ve agonised over this issue and <a
title="Research into Possible Domain Model Solutions " href="http://www.rvdavid.net/zend-framework-model/" target="_blank">blogged about my progress</a>. Some weeks or days later I tried to probe the <a
title="How would you handle this? – Service Layer slowly getting polluted (or so it seems)! - Damn was I confused!" href="http://www.rvdavid.net/how-would-you-handle-this-service-layer-slowly-getting-polluted-or-so-it-seems/" target="_blank">community on what they would do</a>, Now I think I&#8217;d have an idea on what I would do.</p><p>After some more thought and lots of research on the subject, I&#8217;ve come to a solid point where I actually have something to try out which seems semantic aside from the naming of the class (Service Class) &#8211; but this is derived from what some people are talking about in ZF circles starting from Matthew Weier O&#8217;Phinney who was coining it as the &#8220;<a
title="check out the part with the sub heading: gateway to the domain" href="http://weierophinney.net/matthew/archives/202-Model-Infrastructure.html" target="_blank">Gateway to the Domain</a>&#8221; from early on, then later changing it to &#8220;Service Class&#8221;.</p><p><span
id="more-307"></span></p><h3>The Service Class</h3><p>So this is what I chose to go with:  For each model class, I&#8217;ve got a Database Agnostic Service class - in fact, it uses the Entities Produced by Doctrine ORM to talk to the database, but isn&#8217;t entirely reliant upon Doctrine to Provide the Model Layer on it&#8217;s own. Using Doctrine as your Model Layer alone I suppose is better than extending Zend_Db which is highly <a
title="Me getting schooled on Why Extending from Zend_Db is bad at Nabble" href="http://n4.nabble.com/Another-Model-Design-Thread-td670076.html" target="_blank">discouraged by everyone</a>, but you still have the database dependency.</p><p>I thought well, I&#8217;ve done a lot of feeling around the subject, maybe I&#8217;ll just ask around. So over to twitter I go. I sent <a
title="Dude, I always gotta go to your site to get your name! I can never spell it correctly!" href="http://weierophinney.net/matthew/" target="_blank">Matthew Weier O&#8217;Phinney</a> a tweet asking if it is right that Doctrine models are relatively empty whilst Model services are filled with business logic and <a
href="http://twitter.com/weierophinney/status/7464401031" target="_blank">he answered</a>: &#8220;Absolutely. Plain old PHP is perfect for entities.&#8221; but I had no idea WTF that meant.</p><p>The Service Layer uses the Model which is the Entity. <a
href="http://twitter.com/rvdavid/status/7465840295">My further attempt</a> to clarify the situation and continue discussion didn&#8217;t get a response &#8211; maybe because I had to condense words and use accronymns to fit the message in or he had just become too busy. So on my own I go again.</p><p>After mulling over it a few, I thought I&#8217;d just run with what I&#8217;ve got. It seems to be semantic, but it has a lot of responsibilities:</p><ul><li>The Model Service Class is a Resource.</li><li>The Model Service uses the ACL layer to check if a Role Identified has the Privileges to make it&#8217;s request prior to usage.</li><li>The Model Service creates Entities by using its Model Factory/Finder methods such as FindById it then returns either an array or an Entity based on what Hydration mode was specified (default is array).</li><li>The Model Service creates Forms and uses it for Validation</li><li>The Model Service provides the CRUD methods so that the Controller does not have to worry about instantiating and configuring models to Create Update or Delete data.</li><li>The Model Service uses Zend_Cache and can use caching on non-changing data such as lookup lists status or types and large collections of data used in drop downs, lists or datagrids.</li><li>Although there is no factory for it, the Model Service can create and use other Model Service classes.</li><li><del
datetime="2010-05-05T03:45:29+00:00">The Service Layer is not passed to the View either. The View is configured by the Controller and has data shoved into properties/member variables.</del></li><li>The Service Object can be passed to the View if required, so that the View can use the Sevice object to interrogate models on it&#8217;s own. We trust that those writing the View Markup will only be using the service object _strictly for reading only_.</li></ul><p>I&#8217;ve been working with this setup for a few weeks now. This method is very testable and makes for an extremely thin Controller Layer.</p><p>What do you guys think?</p><p>Have we over engineered this thing? Should it be called the Service Layer as more and more people are coining it as? What suggestions can you make to make this better?</p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/my-zend-framework-model-layer-part-service-part-orm/feed/</wfw:commentRss> <slash:comments>37</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 4/11 queries in 0.019 seconds using disk

Served from: www.rvdavid.net @ 2010-09-10 20:22:01 -->