The ORM anti-pattern and other solutions

In his insightful blog post titled “ORM is an anti-pattern“, Laurie Voss makes a bold statement. I agree with him. I never really liked ORM, anyway. Here is what I think about this matter: 

ORM is a solution to a problem. That of impedance mismatch between using objects in a program and storing them in a relational database. As I just wrote, ORM is a solution to this problem.  “A” solution.  One of the solutions. So what are all the possible solutions?

One solution could be to use objects and store them in an object database and not in a relational one.

A second solution could be to not use objects at all. Or, rather, use objects, but not those that emerge from the problem domain and the user requirements, but those that are specific to the relational database schema. What I mean is that each object could correspond to a row in a relational table. I am not a developer, but if I had to write a program, this method would be on the top of my list. I have thought of this method myself, but it would not surprise me if others have thought of this method, too.

A third solution could be to use objects, store them in a relational database and handle storage and retrieval ourselves using SQL statements.

And a fourth solution could be to use objects, store them in a relational database and use  ORM to handle storage and retrieval, avoiding the use of SQL statements.

In the event that you find one of the first three solutions to be optimal for the problem at hand, then ORM may certainly be an anti-pattern to you (again, for the problem at hand). In the event that you decide that the fourth solution is the way to go, then ORM may not be an anti-pattern to you.

What I hope I have proven here, is that there are cases where ORM is an anti-pattern.

Now, Laurie Voss takes this a step further and argues that ORM is an anti-pattern more often than not. I agree with his “statistics”. But there can certainly be cases where the use of ORM may be beneficial. To ORM or not to ORM is one of those tough choices developers have to make (and live with them).

Advertisements

About Dimitrios Kalemis

I am a systems engineer specializing in Microsoft products and technologies. I am also an author. Please visit my blog to see the blog posts I have written, the books I have written and the applications I have created. I definitely recommend my blog posts under the category "Management", all my books and all my applications. I believe that you will find them interesting and useful. I am in the process of writing more blog posts and books, so please visit my blog from time to time to see what I come up with next. I am also active on other sites; links to those you can find in the "About me" page of my blog.
This entry was posted in Development. Bookmark the permalink.