views:

383

answers:

5

I've read about and dabbled with some including active record, repository, data transfer objects. Which is best?

+3  A: 

'Best' questions are not really valid. The world is filled with combination and variations. You should start with the question that you have to answer: What problem are you trying to solve. After you answer that you look at the tools that work best with the issue.

Arthur Thomas
+3  A: 

While I agree "best" questions are not the greatest form (since they are so arbitrary), they're not totally irrelevant either.

In the world constructed here at S.O. where developers vote on what's "best", why not have best questions? "Best questions" prompt discussion and differing opinions.

Eventually, when someone "googles" 'data access pattern' they should come to this page and see a plethora of answers then, right?

Ian Patrick Hughes
But it gives no insight into a particular problem that is trying to be solved. I think wikipedia is better for finding lists of tools to use than SO would be.
Arthur Thomas
I totally understand what you are saying, but not every question is "particular". Standing at the precipice of starting a new project you might want insight into a set competing technologies. "Best" can be shorthand for a SPECIFIC pros-cons list from the audience in some ways. Wikipedia? S.O., man!
Ian Patrick Hughes
I really don't have anything against the discussion, but people tend to latch on the the word 'best' like they do the word 'enterprise'.
Arthur Thomas
+1  A: 

It really depends on your task. At least you should know and understand all database access patterns to choose one most suitable for current problem.

Sergei Stolyarov
I guess if I knew and understood all database access patterns, I wouldn't be asking the question. :)
Jim
+1  A: 

This is a good question which should provoke some thought.
Database access is often not subject to rigorous testing - particularly not automated testing, and I would certainly like to increase the amount of testing on my database.

I'm using the MbUnit test framework running from inside Visual Studio to do some testing.
Our application uses stored procedures wherever possible, and the tests I have written set up the database for testing, call a stored procedure, and check the results.
For a collection of related stored procedures, we have a C# file with tests for those stored procs. (However, our coverage is probably about 1% so far!).

Active record is an attractive option because of Ruby's built-in emphasis on automated testing. If I were starting over, that would be a point for using active record.

AJ
+1  A: 

Repository is probably the best pattern for testability since it allows you to replace a repository with a mock when you need to test. ActiveRecord ties your models to the database (convenient sometimes, but generally more dificcult to test).

Alvaro