Method Names for Data Retrieval

Ben Nadel recently posted a blog entry about moving queries to service layers (something I am a big fan of). Both the blog entry and the comments that followed were great and well worth the read. I especially liked Hal Helm's comment about differentiating between queries that are necessarily the same and those that are accidentally the same.

One thing that came up in this discussion was how to name the methods that retrieve data. One example was "getArticlesByAuthorID()" (I'm just picking one of many that followed this pattern). To me, this is a code smell. The method name describes not only what you want, but how you are going to get it.

I would do it differently.

[More]

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
I agree with you. Sean C. made a comment on Ben's post to the effect of having the arguments reflect the intent of your method call. So getArticles(authorid="5") or getArticles(active=true), etc. I like that approach, but there seemed to be people who wanted more "expressive" method names. So I suggested writing facade methods where getArticlesByID() calls getArticles(id=). I personally don't do that, but it was just a suggestion I put out if more descriptive names were desired.
# Posted By Tony Garcia | 6/19/09 3:21 PM
Tony,

Thanks for the words of support. I am actually not certain if anyone was positively suggesting that source of action (I read through the comments rather quickly), but it spurred my thought to share how I would handle the situation.
# Posted By Steve Bryant | 6/19/09 8:44 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.