<?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: ActiveRecord, the ugly design pattern</title>
	<atom:link href="http://damieng.com/blog/2007/05/07/activerecord-the-ugly-design-pattern/feed" rel="self" type="application/rss+xml" />
	<link>http://damieng.com/blog/2007/05/07/activerecord-the-ugly-design-pattern?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=activerecord-the-ugly-design-pattern</link>
	<description>A .NET developer in silicon valley</description>
	<lastBuildDate>Sun, 25 Dec 2011 15:10:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Jimmy Zimms</title>
		<link>http://damieng.com/blog/2007/05/07/activerecord-the-ugly-design-pattern#comment-29199</link>
		<dc:creator>Jimmy Zimms</dc:creator>
		<pubDate>Wed, 04 Nov 2009 16:29:01 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2007/05/07/activerecord-the-ugly-design-pattern.aspx#comment-29199</guid>
		<description>Millions years too late but what the hell, why not post? ;)

It behooves me to mention that most of the time I happen to see Active Record pattern actually in use by non trivial applications is actually as a bridge between domain layers and an ORM itself. While being able to reconstitute a domain entity from the ORM and gain all the tastey wonderfullness that comes with it (auto session management, entity maps, less code, and now query providers) so far all the major vendors still all leak nondomain requirements into the objects, namely the requirement for a parametereless constructor and virtual and/or writeable properties. For some people this is a make or break issue so they bridge them via AR. That of course opens another can of worms but I can totally see where some people are coming from.</description>
		<content:encoded><![CDATA[<p>Millions years too late but what the hell, why not post? ;)</p>
<p>It behooves me to mention that most of the time I happen to see Active Record pattern actually in use by non trivial applications is actually as a bridge between domain layers and an ORM itself. While being able to reconstitute a domain entity from the ORM and gain all the tastey wonderfullness that comes with it (auto session management, entity maps, less code, and now query providers) so far all the major vendors still all leak nondomain requirements into the objects, namely the requirement for a parametereless constructor and virtual and/or writeable properties. For some people this is a make or break issue so they bridge them via AR. That of course opens another can of worms but I can totally see where some people are coming from.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steve</title>
		<link>http://damieng.com/blog/2007/05/07/activerecord-the-ugly-design-pattern#comment-1841</link>
		<dc:creator>steve</dc:creator>
		<pubDate>Mon, 14 May 2007 20:11:18 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2007/05/07/activerecord-the-ugly-design-pattern.aspx#comment-1841</guid>
		<description>It&#039;s not ActiveRecord that&#039;s ugly, it&#039;s the implementation of it. Whether or not to make the &#039;finder&#039; methods static or put them in another, single-instance class is stylistic more than anything else - in both cases the implementations should be using a more generic implementation to do things like cacheing - whether that&#039;s done through delegation or inheritence will influence where you put those methods. I&#039;ve seen it done both ways and both are adequate. Static methods of any kind are inherently a separation of responsibility, since by nature they cannot be instance-sensitive. Not using them in this case because of that actually implies that they should never be used. In fact static methods are useful where the implementation is domain-specific but not state-specific. Finder methods can actually fit that description, depending on implementation, although arguably because they all do similar things they would be better placed in an external class with policy / attribute-oriented behaviour rather than a domain-specific location.  &lt;br /&gt;&lt;br /&gt;ActiveRecord works well as a pattern for simple stuff, but even in larger systems you&#039;ll probably find that a reasonable proportion of your classes fit it ok. Therefore being able to mix it with more complex mappings is the most pragmatic approach - have an automatic mapping for those that can use it, and manual mapping otherwise. &lt;br /&gt;&lt;br /&gt;Also, since overly deep inheritence structures can be limiting in their own right (the age old example of Person and subclasses Employee and Customer, but what happens if your employee is also a customer sometimes .. doh), I actually find that data inheritence is less of a problem in practice than it is in theory. Where it is necessary to have data inheritence, a case-by-case approach tends to be best rather than blanket application of one pattern. After all, it depends on the data mix / distribution as to which will be most appropriate - STI will be fine if there&#039;s only one or two small attributes, one of the other two will be more useful when there are bigger differences. And if you mapper is smart enough, you can switch between them if the data mix changes as the application evolves.&lt;br /&gt;&lt;br /&gt;</description>
		<content:encoded><![CDATA[<p>It&#8217;s not ActiveRecord that&#8217;s ugly, it&#8217;s the implementation of it. Whether or not to make the &#8216;finder&#8217; methods static or put them in another, single-instance class is stylistic more than anything else &#8211; in both cases the implementations should be using a more generic implementation to do things like cacheing &#8211; whether that&#8217;s done through delegation or inheritence will influence where you put those methods. I&#8217;ve seen it done both ways and both are adequate. Static methods of any kind are inherently a separation of responsibility, since by nature they cannot be instance-sensitive. Not using them in this case because of that actually implies that they should never be used. In fact static methods are useful where the implementation is domain-specific but not state-specific. Finder methods can actually fit that description, depending on implementation, although arguably because they all do similar things they would be better placed in an external class with policy / attribute-oriented behaviour rather than a domain-specific location.  </p>
<p>ActiveRecord works well as a pattern for simple stuff, but even in larger systems you&#8217;ll probably find that a reasonable proportion of your classes fit it ok. Therefore being able to mix it with more complex mappings is the most pragmatic approach &#8211; have an automatic mapping for those that can use it, and manual mapping otherwise. </p>
<p>Also, since overly deep inheritence structures can be limiting in their own right (the age old example of Person and subclasses Employee and Customer, but what happens if your employee is also a customer sometimes .. doh), I actually find that data inheritence is less of a problem in practice than it is in theory. Where it is necessary to have data inheritence, a case-by-case approach tends to be best rather than blanket application of one pattern. After all, it depends on the data mix / distribution as to which will be most appropriate &#8211; STI will be fine if there&#8217;s only one or two small attributes, one of the other two will be more useful when there are bigger differences. And if you mapper is smart enough, you can switch between them if the data mix changes as the application evolves.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dies-el</title>
		<link>http://damieng.com/blog/2007/05/07/activerecord-the-ugly-design-pattern#comment-1840</link>
		<dc:creator>dies-el</dc:creator>
		<pubDate>Tue, 08 May 2007 23:19:41 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2007/05/07/activerecord-the-ugly-design-pattern.aspx#comment-1840</guid>
		<description>Hey Damieng,&lt;br /&gt;&lt;br /&gt;I believe Rails achieves Single Table Inheritance by adding an extra column (named &#039;type&#039;) to the table that lets rails know what model to use for what data. The model classes you then make use that invisibly to make sure they access the correct data.&lt;br /&gt;&lt;br /&gt;On a side note, the Rails book (Agile Web Develoblah, pg 341) does carry lots of warnings as to whether you should actually use STI or whether you should go for another method of categorising (e.g. tagging).</description>
		<content:encoded><![CDATA[<p>Hey Damieng,</p>
<p>I believe Rails achieves Single Table Inheritance by adding an extra column (named &#8216;type&#8217;) to the table that lets rails know what model to use for what data. The model classes you then make use that invisibly to make sure they access the correct data.</p>
<p>On a side note, the Rails book (Agile Web Develoblah, pg 341) does carry lots of warnings as to whether you should actually use STI or whether you should go for another method of categorising (e.g. tagging).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

