Rockstar Engineering

Back to the Basics: the DAO pattern.

Posted in Software Design, Software Development by Jose Asuncion on February 19, 2012

I learned about the DAO pattern during my internship and I have been using it ever since. Now, I don’t know what it is that bothers me but I think it is ugly and I am thinking of having a look at the Repository Pattern. Though the DAO does a good job of decoupling code, one thing that annoys me is that a typical dao class I have handled has so many methods, some of them really specific and hints at the long queries that they execute.

To illustrate here is how one of my current dao api looks like (translated to Java from PHP just because I miss Java):

public class WallDao {
   public Wall getWallById(int id) {}
   public String getAppNameByWallId(int id) {} 
   public String getAppDetailsByWallId(int id) {} 
   public String getHomeArticles(int applicationId) {} 
   public String getWallArticles(int wallArticles) {} 
   public Settings getWallSettings(int id) {}
   public void update(Wall wall) {}
   public void disableFeatures(id moduleId, 
       List displayPositions) {}
   public List<Article> getWallFeaturesFull(int moduleId) {}
   public List<Article> getWallFeatures(int moduleId) {}

I guess I am all confused now so today I went back to the basics again and read this article at IBM Developer Works. The most interesting tidbit is a list of what a dao what might look like and is outlined under the Dao Implementation section.

I guess I have been doing it wrong all this time.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: