<?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>comfuzius</title>
	<atom:link href="http://www.comfuzius.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.comfuzius.de</link>
	<description>Fachchinesisch für Entwickler</description>
	<lastBuildDate>Tue, 18 Aug 2009 13:25:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>de</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Models im Zend Framework (I)</title>
		<link>http://www.comfuzius.de/sagt/models-im-zend-framework-i/</link>
		<comments>http://www.comfuzius.de/sagt/models-im-zend-framework-i/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 13:06:28 +0000</pubDate>
		<dc:creator>awu</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.comfuzius.de/?p=9</guid>
		<description><![CDATA[Im Zend Framework gibt es keine Basisklassen für Models, also etwa eine Klasse Zend_Model. Man ist der Auffassung, dass Models die Applikationslogik enthalten und daher grundsätzlich applikationsspezifisch sind und demnach nicht Bestandteil eines Framewoks, das ja verallgemeinerungsfähige Prinzipien implementiert, sein können.
Bill Karvin begründet dies in seinem Artikel ActiveRecord does not suck.
Wikipedia definiert ein Model wie [...]]]></description>
			<content:encoded><![CDATA[<p>Im Zend Framework gibt es keine Basisklassen für Models, also etwa eine Klasse <code>Zend_Model</code>. Man ist der Auffassung, dass Models die Applikationslogik enthalten und daher grundsätzlich applikationsspezifisch sind und demnach nicht Bestandteil eines Framewoks, das ja verallgemeinerungsfähige Prinzipien implementiert, sein können.<span id="more-9"></span></p>
<p>Bill Karvin begründet dies in seinem Artikel<span class="post-author vcard"><span class="fn"> </span></span><a title="ActiveRecord does not suck" href="http://karwin.blogspot.com/2008/05/activerecord-does-not-suck.html" target="_blank">ActiveRecord does not suck.</a></p>
<p>Wikipedia definiert ein <a title="Model View Controller" href="http://de.wikipedia.org/wiki/MVC#Modell_.28model.29" target="_self">Model</a> wie folgt:</p>
<blockquote><p>Das Modell enthält die darzustellenden Daten und gegebenenfalls (abhängig von der Implementation des MVC-Patterns) auch die Geschäftslogik. Es ist von Präsentation und Steuerung unabhängig. Die Bekanntgabe von Änderungen an relevanten Daten im Modell geschieht nach dem <span class="mw-redirect">Entwurfsmuster „Beobachter“</span>. &#8230;</p>
<p>Bei Webanwendungen kann der Browser nicht nach dem Observer-Muster unmittelbar auf Änderungen des Models auf dem Server reagieren. Jede Antwort (HTTP-Response) an den Browser setzt im HTTP-Protokoll eine Anfrage (HTTP-Request) voraus. Man spricht vom Request-Response-Cycle. Daraus folgt, dass das Observer-Muster auch auf Seiten des Servers seine Vorteile nicht ausspielen kann. Weil es dann nur einen Mehraufwand bedeuten würde, kommt es typischerweise nicht zum Einsatz. <strong>Stattdessen tritt meist der Controller als aktiver Vermittler zwischen Model und View im Rahmen eines Request-Response-Cycles auf</strong>.</p></blockquote>
<p>Nach einem <a title="The M in MVC: Why Models are Misunderstood and Unappreciated" href="http://blog.astrumfutura.com/archives/373-The-M-in-MVC-Why-Models-are-Misunderstood-and-Unappreciated.html" target="_self">Artikel</a> von Padraic Brady hat ein Model mindestens zwei Aufgaben:</p>
<ul>
<li>den Status zwischen zwei Requests zu sichern und</li>
<li> die gesamte Geschäftslogik zu impelmentieren, die einen solchen Status erzeugt und wiederspiegelt</li>
</ul>
<p>Das Model repräsentiert demnach die Daten, den Zustand und die Geschäftslogik des Systems. Dies ist das sogenannte &#8220;Skinny Controller &#8211; Fat Model &#8211; Prinzip&#8221;.</p>
<p>Üblicherweise wird die Applikationslogik im Controller untergebracht.</p>
<blockquote><p>Most people simply assumed that MVC worked as follows: requests go to Controllers, Controllers get data from Model, Controller gives Model data to View, Controller renders View. In other words: Controller, Controller, Controller, Controller.</p></blockquote>
<p>Brady formuliert dazu seinen Meinung recht drastisch:</p>
<blockquote><p>Since Models are so lame to developers, they invented a new concept. Fat Stupid Ugly Controllers (FSUC). I put the SUC in FSUC on purpose. It seemed funny at 10pm after a few drinks. And less offensive than FUC. These were invented since Models were strange, alien, and possible terrorist entities nobody really trusted with anything other than data access methods.</p>
<p>In my mind, the best Controller is a Controller which doesn&#8217;t need to exist</p></blockquote>
<p>Neben der daraus resultierender Unübersichtlichkeit im Code führt Brady ein weiters wichtiges Argument für Fat Models ein:</p>
<blockquote><p>The nature of Controllers is such that they are tightly coupled to the underlying framework. You can only make a Controller execute by initialising the entire framework&#8217;s MVC stack (potentially dozens of other class dependencies!).</p></blockquote>
<p>Dies ist dann auch ein starkes Argument gegen allzu viel Model-Basislogik im Framework, ähnlich wie es Bill Karvin begründet.</p>
<p>Brady schlussfolgert:</p>
<blockquote><p>Models are just a collection of loosely coupled classes. You can instantiate and call them from anywhere &#8211; other Models, Controllers and even Views! A Controller, on the other hand, is a tightly integrated cog in the machinery of a whole process. You can&#8217;t reuse a Controller without also dragging in the entire process of setting up request objects, dispatching, applying action helpers, initiating the View, and handling returning response objects.</p></blockquote>
<p>Im Tutorial für das AGAVI-Framework wird das Model wie folgt definiert:</p>
<blockquote><p>Models are classes that contain your application logic. They       access databases, send e-mails, render images, converse with       captcha libraries and facilitate the processing of any other       data that an application needs. Models are completely       disconnected from the user interface of your applications, and       Agavi never interacts with them directly.</p>
<p>Actions manipulate your Models using outside data to perform       changes to your application state. Views question the Models for       relevant data and display it.</p>
<p>When you remove the user interface layer (Actions and Views)       all that remains is Models — your application expressed as an       API. When your application is available as an API, you can write       automated tests to make sure it doesn&#8217;t break throughout its       development.</p></blockquote>
<h2>Schlussfolgerungen</h2>
<ul>
<li>Models sind keine einfachen Datenspeicherobjekte, sondern implementieren Applikationslogik.</li>
<li>Models müssen die darunterliegende Datenspeicherung verbergen. Die Model-Schnittstelle darf also weder Datenbankcode noch Tabellenspalten oder ähnliches enthalten</li>
<li>Aufgabe der Models ist es
<ul>
<li>Daten zu validieren anhand von Geschäftskriterien,</li>
<li>die Daten in die zu speichernde Form umzuwandeln (Normalisierung) und</li>
<li>andersherum, die Speicherrepräsentation der Daten in ihre Darstellungsform z.B. durch Lokalisierung zu wandeln</li>
</ul>
</li>
</ul>
<p>Hier eine zusammenfassende Übersicht über relevante Artikel:</p>
<ul>
<li><a title="http://blog.mikeseth.com/index.php?/archives/4-ActiveRecord-sucks,-but-Kore-Nordmann-is-wrong.html#extended" href="http://blog.mikeseth.com/index.php?/archives/4-ActiveRecord-sucks,-but-Kore-Nordmann-is-wrong.html#extended" target="_blank">ActiveRecord sucks, but Kore Nordmann is wrong</a></li>
<li><span class="post-author vcard"><span class="fn">Bill Karwin: </span></span><a title="ActiveRecord does not suck" href="http://karwin.blogspot.com/2008/05/activerecord-does-not-suck.html" target="_blank">ActiveRecord does not suck</a></li>
<li>Padraic Brady: <a title="The M in MVC: Why Models are Misunderstood and Unappreciated" href="http://blog.astrumfutura.com/archives/373-The-M-in-MVC-Why-Models-are-Misunderstood-and-Unappreciated.html" target="_blank">The M in MVC: Why Models are Misunderstood and Unappreciated</a></li>
<li>Dave Marshall: <a title=" Fat Models and the Data Access Layer" href="http://www.davedevelopment.co.uk/2008/06/17/fat-models-and-the-data-access-layer/" target="_blank">Fat Models and the Data Access Layer</a></li>
<li>Matthew Weier O&#8217;Phinney: <a title="Model Infrastructure" href="http://weierophinney.net/matthew/archives/202-Model-Infrastructure.html" target="_blank">Model Infrastructure</a></li>
<li>Matthew Weier O&#8217;Phinney: <a title="Using Zend_Form in Your Models" href="http://weierophinney.net/matthew/archives/200-Using-Zend_Form-in-Your-Models.html" target="_blank">Using Zend_Form in Your Models</a></li>
<li>Matthew Weier O&#8217;Phinney: <a title="Applying ACLs to Models" href="http://weierophinney.net/matthew/archives/201-Applying-ACLs-to-Models.html" target="_blank">Applying ACLs to Models</a></li>
<li>Implementierung von Matthew Weier O&#8217;Phinney: <a href="http://github.com/weierophinney/pastebin/tree/bugapp" target="_blank">PasteBin-Anwendung</a></li>
<li>Rob Allen: <a title="On models in a Zend Framework application" href="http://akrabat.com/2008/12/13/on-models-in-a-zend-framework-application/" target="_blank">On models in a Zend Framework application</a></li>
<li>Jani Hartikainen: <a title="Decoupling models from the database: Data Access Object pattern in PHP" href="http://codeutopia.net/blog/2009/01/05/decoupling-models-from-the-database-data-access-object-pattern-in-php/" target="_blank">Decoupling models from the database: Data Access Object pattern in PHP</a></li>
<li>Ralf Eggert: <a title="Zend_Model - Stand der Dinge" href="http://www.ralfeggert.de/2008/09/21/zend_model-stand-der-dinge/" target="_blank">Zend_Model &#8211; Stand der Dinge</a></li>
<li>Ralf Eggert: <a title="Das M im MVC-Entwurfsmuster" href="http://www.ralfeggert.de/2008/12/09/das-m-im-mvc-entwurfsmuster/" target="_blank">Das M im MVC-Entwurfsmuster</a></li>
<li>Jurriën Stutterheim: <a title="Zend_Model Component Proposal" href="http://framework.zend.com/wiki/pages/viewpage.action?pageId=41564" target="_blank">Zend_Model Component Proposal</a></li>
<li><a title="AGAVI Tutorial" href="http://www.agavi.org/documentation/tutorial/mvc-in-agavi.html" target="_blank">Das AGAVI MVC Framework</a></li>
<li><a href="http://code.google.com/p/zend-framework-orm/" target="_blank">Zend Framework Db Table ORM</a></li>
<li><span class="fn">Maarten Balliauw:</span><a title="PHPLinq" href="http://blog.maartenballiauw.be/post/2009/01/29/PHPLinq-040-released-on-CodePlex!.aspx" target="_blank"><span class="fn"> </span>PHPLinq</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.comfuzius.de/sagt/models-im-zend-framework-i/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
