Blog Stats
  • Posts - 99
  • Articles - 5
  • Comments - 96
  • Trackbacks - 106

 

Repository vs ActiveRecord

Warning this post is not well formulated but has some useful random information :)

There has been alot of talk lately about people refactorring from the repository pattern to the Active Record pattern. For instance Sam Gentile brings it up here

How prevalent is this movement? I personally prefer the repository pattern over ActiveRecord for quite a few reasons.

  1.  My db objects and domain objects rarely match up.
  2.  I often use polymorphism on my repositories (especially for testing).
  3.  I can write a generic repository (reusing code for general methods such as Delete or FetchByQuery)
  4.  I can allow repository injection by the domain host.
  5. A Repository shows explicitly a decision to make the object an aggregate root 
  6. I use alot of AOP and its nice being able to place aspects on my repositories, this could not be done with active record's static methods
  7. ActiveRecord seems to defeat the entire concept of DDD, ActiveRecord promotes a database centric model

skeleton example of generic repository

public class Repository {
    public virtual List FetchByQuery(QueryObject _Query) {
    }
    public virtual void Save(T _Object) {
    }
    public virtual void Delete(T _Object) {
    }
}

I guess the big question in choosing which way to go is whether or not your object creations varies for a given object. If you only ever have a single repository then perhaps you are probably better off with the static accessors. Personally I prefer the seperation (and the code saving).


Unit Testing

The very concept of a repository is that it gives the impression of an in memory database. This works perfectly for unit testing as I can just use a repository that actually holds all of its data in memory for testing purposes! I can in fact even make a generic based one that can operate on my query objects using reflections.

also .. some interesting links I happenned accross:

http://www.xprogramming.com/xpmag/jatSustainablePace.htm 
http://www.joelonsoftware.com/items/2006/04/11.html
http://media.spikedhumor.com//805/zoomquilt.swf very dali'esque


Feedback

# sharegyan:-share market tips

Gravatar Hi,

Your blog is nice and informative. We would like to share few information’s with users.
At this point of time Indian Stock Market
is looking bullish in short term still its in bearish mood in medium term. Nifty good till 4700 and
this target will be achieved very soon. We can see some profit booking from these levels. Nifty major support is 3650 and major resistance is 5200 in months ahead.
Investors should grab fundamentally strong shares at every fall. There are lot many shares available at throw away prices at this point of time.



For any doubt please feel free to ask us.


Thanks

Regards

SHARETIPSINFO TEAM


8/26/2008 1:39 AM | sharegyan.gyan

# re: Repository vs ActiveRecord

Gravatar I have just checked this blog and I have found this to be very informative and useful. This blog must be very helpful to its visitors.

Stock market is a volatile market. Where people invest with the intention of making money but many traders and investors end up as a looser. Must be wondering what makes one trader a winner in the stock market and another one as a looser in the market.

In Indian stock market many people have many doubts but they don’t want to clear them by consulting professionals nor they want to raise there questions where other traders and investors can help them out. But now many portals are coming up with QNA sections where investors and traders can exchange there views about stock and stock market. Indeed it’s a great help for everyone who are related to stock market.

Stock Trading India 7/17/2009 6:38 AM | India Stock Tips

Post a comment





 

 

 

Copyright © Greg Young