<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: How would you handle this? &#8211; Service Layer slowly getting polluted (or so it seems)!</title>
	<atom:link href="http://www.rvdavid.net/how-would-you-handle-this-service-layer-slowly-getting-polluted-or-so-it-seems/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rvdavid.net/how-would-you-handle-this-service-layer-slowly-getting-polluted-or-so-it-seems/</link>
	<description>A periodical blog of experiences from the angle of an autodidactic, paranoid and narcissistic web developer...</description>
	<lastBuildDate>Thu, 04 Mar 2010 21:21:10 +1100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<meta xmlns="http://www.w3.org/1999/xhtml" name="robots" content="noindex,follow" />
	<item>
		<title>By: rvdavid</title>
		<link>http://www.rvdavid.net/how-would-you-handle-this-service-layer-slowly-getting-polluted-or-so-it-seems/#comment-1022</link>
		<dc:creator>rvdavid</dc:creator>
		<pubDate>Fri, 22 Jan 2010 04:45:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rvdavid.net/?p=168#comment-1022</guid>
		<description>Hi Tomas, 

Yeah this was a while ago - it seems the example you&#039;ve written comes in from a plausible angle and is somewhat similar to the direction I&#039;ve taken here: 

http://www.rvdavid.net/my-zend-framework-model-layer-part-service-part-orm/

Thank you for your feedback, I appreciate it greatly.</description>
		<content:encoded><![CDATA[<p>Hi Tomas, </p>
<p>Yeah this was a while ago &#8211; it seems the example you&#8217;ve written comes in from a plausible angle and is somewhat similar to the direction I&#8217;ve taken here: </p>
<p><a href="http://www.rvdavid.net/my-zend-framework-model-layer-part-service-part-orm/" rel="nofollow">http://www.rvdavid.net/my-zend-framework-model-layer-part-service-part-orm/</a></p>
<p>Thank you for your feedback, I appreciate it greatly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tomas</title>
		<link>http://www.rvdavid.net/how-would-you-handle-this-service-layer-slowly-getting-polluted-or-so-it-seems/#comment-963</link>
		<dc:creator>Tomas</dc:creator>
		<pubDate>Thu, 21 Jan 2010 04:55:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rvdavid.net/?p=168#comment-963</guid>
		<description>Hi,

bases on the OOP rule called &#039;Single Responsibility Principle&#039; (http://giorgiosironi.blogspot.com/2009/09/solid-part-1-single-responsibility.html)
) I would recommend to create UpdateService service and keep it separate from the UserService, because that import can have various source and could also write to different Entities.

That UpdateService could have following features:
*) read from various sources based on provided adapter (csv, xls, SOAP etc) http://giorgiosironi.blogspot.com/2010/01/practical-php-patterns-adapter.html
*) write to various Entities that can be just injected through some generic setOptions() or reflection (etc...)

The above would keep the UserService thin and move this additional functionality into another class,
that can handle this functionality well and is not coupled only to User.

Some example:

$fileCsv = $form-&gt;getUploadedFileContent();

$adapter = new CsvAdapter($fileCsv);

$updateHandler = new UpdateService($adapter);
$userService   = new UserService();

$updateHandler-&gt;updateEntities($userService);

class UpdateService {

  ///

  public function updateEntities(BusinessService $service) {
  
    foreach ($this-&gt;getAdapter()-&gt;getRows() as $row) {
      $entity = $Service-&gt;findById($row-&gt;getId());
      
      // This can be done various ways and even can be some checking included.
      $entity-&gt;loadFromArray($row-&gt;toArray());
      
      $service-&gt;save($entity);
    }
  
  }
}

PS: thanks giorgio for all his blogs :)</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>bases on the OOP rule called &#8216;Single Responsibility Principle&#8217; (<a href="http://giorgiosironi.blogspot.com/2009/09/solid-part-1-single-responsibility.html" rel="nofollow">http://giorgiosironi.blogspot.com/2009/09/solid-part-1-single-responsibility.html</a>)<br />
) I would recommend to create UpdateService service and keep it separate from the UserService, because that import can have various source and could also write to different Entities.</p>
<p>That UpdateService could have following features:<br />
*) read from various sources based on provided adapter (csv, xls, SOAP etc) <a href="http://giorgiosironi.blogspot.com/2010/01/practical-php-patterns-adapter.html" rel="nofollow">http://giorgiosironi.blogspot.com/2010/01/practical-php-patterns-adapter.html</a><br />
*) write to various Entities that can be just injected through some generic setOptions() or reflection (etc&#8230;)</p>
<p>The above would keep the UserService thin and move this additional functionality into another class,<br />
that can handle this functionality well and is not coupled only to User.</p>
<p>Some example:</p>
<p>$fileCsv = $form-&gt;getUploadedFileContent();</p>
<p>$adapter = new CsvAdapter($fileCsv);</p>
<p>$updateHandler = new UpdateService($adapter);<br />
$userService   = new UserService();</p>
<p>$updateHandler-&gt;updateEntities($userService);</p>
<p>class UpdateService {</p>
<p>  ///</p>
<p>  public function updateEntities(BusinessService $service) {</p>
<p>    foreach ($this-&gt;getAdapter()-&gt;getRows() as $row) {<br />
      $entity = $Service-&gt;findById($row-&gt;getId());</p>
<p>      // This can be done various ways and even can be some checking included.<br />
      $entity-&gt;loadFromArray($row-&gt;toArray());</p>
<p>      $service-&gt;save($entity);<br />
    }</p>
<p>  }<br />
}</p>
<p>PS: thanks giorgio for all his blogs <img src='http://www.rvdavid.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
