logo
  • Jobs
  • About Me
  • Contact
  • Home

Archive for May, 2005

The Polymorphic Podcast

Via David Starr, I found the Polymorphic Podcast. The idea of podcasting is fascinating, syndicated audio content. This specific podcast aims to help make you a better developer. I’ve listened to a few now and am quite impressed.

You should give Craig a listen.

No Comments

Pluggable Data Access Layer using Abstract Factory

Recently, I made some changes to an application that I have been working on. The requirement was to support different data stores. As written, the application only supported MS SQL Server. I had hoped to allow this application to run on top of an Oracle database or even a pile of xml sitting on the file system.

To do this, I needed to find a way to abstract the implementation of the Data Access Layer (DAL) from the rest of the program. The approach I came up with involved the Data Mapper pattern and Abstract Factory.

For the Data Mapper implementation, I created a CRUD interface for each table in my database. I already had objects defined around the individual rows in the table (ie: Person, Role, etc), so I did not need to do that. Using the Northwind database, I had an interface that looked something like this:

public class Customer
{
    // omitted for brevity
}
 
public interface ICustomerMapper
{
    Customer FindById(string id);
    void Save(Customer customer);
    void Remove(Customer customer);
}

The next step in achieving the pluggable DAL is to create a concrete implementation for the ICustomerMapper. We can create as many implementations for this as we need (ie: OracleCustomerMapper, SqlCustomerMapper, XmlCustomerMapper).

public class SqlCustomerMapper : ICustomerMapper
{
    // implementation omitted for brevity
}

Once we have our implementations in order, the last thing we need to do is author the abstract factory that our application can use to get at the implementations.

public abstract class NorthwindDataFactory
{
    public abstract ICustomerMapper CustomerMapper { get; }
    public abstract IOrdersMapper OrdersMapper { get; }
    public abstract IRegionMapper RegionMapper { get; }
    // remaining data mappers omitted for brevity
 
    public virtual void Initialize(IDictionary config)
    {
    }
 
    public static NorthwindDataFactory NewInstance()
    {
        string providerType = ConfigurationSettings.AppSettings["dataProviderType"];
        Type type = Type.GetType(providerType, true);
        return (NorthwindDataFactory)Activator.CreateInstance(type);
    }
}
 
public class SqlNorthwindDataFactory : NorthwindDataFactory
{
    public override ICustomerMapper CustomerMapper { get { return new SqlCustomerMapper(); } }
    public override IOrdersMapper OrdersMapper { get { return new SqlOrdersMapper(); } }
    public override IRegionMapper RegionMapper { get { return new SqlRegionMapper(); } }
}

The heart of the abstract factory lies in the NewInstance method. This method uses a configuration setting from the application’s configuration file and uses reflection to instantiate the appropriate implementation. You’ll notice that the base class also has an Initialize method, which can be used to provide any additional configuration items to the concrete factory implementations.

In my particular case, I’ve defined a custom configuration section and am using child nodes to pass values such as connection string into the sql specific factory, and a file path into the xml specific factory.

The best part of this is that anywhere I want to use data services in my application now, I do the following, for example:

ICustomerMapper mapper = NorthwindDataFactory.NewInstance().CustomerMapper;
Customer customer = mapper.FindById("someId");

You see here that the application has no concept of the data storage mechanism. Clients that do not wish to maintain a sql server license can use the xml data factory. Clients that only have an Oracle installation can use the Oracle data factory. The factories get plugged in at runtime with no changes at all to the main application.

I’ve been looking for a clean DAL design for the past year and a half, and I think this design encompasses the best of all worlds. I would be really interested in hearing your thoughts on this.

5 Comments

Hurricanes

While spending last week in Las Vegas for VSLive!, we made a stop by Jimmy Buffett’s Margaritaville. Being a parrothead, this was quite a cool experience for me. During our visit there, I had a Tropical Hurricane, which although good was not quite like the Hurricanes that I’ve managed to whip up here.

I thought Id share the recipe for anyone interested:

  • 2oz Bacardi Light
  • 1oz Bacardi 151
  • 1oz Captain Morgan’s Parrot Bay Coconut Rum
  • 1oz Rose’s Lime
  • 2oz Grenadine
  • 8oz Pineapple-Orange juice
  • 1/2 cup ice cubes

Combine all ingredients in a cocktail shaker, shake and serve in a hurricane glass garnished with orange. Be careful while enjoying; these are pretty lethal… :)

No Comments

Getting Things Done — The Wiki

A few years back, I picked up a copy of Getting Things Done, which is an excellent guide to getting organized by David Allen.

The methods in that book helped me to get my life organized in ways I never thought possible. However, the lack of a good way to keep my inbox resulted in my falling of the GTD bandwagon. Honestly, I’ve been looking for a good way to start this up again, but never did find it… until now.

Enter the GTDTiddlyWiki. This is a very great implementation of the GTD system, which gives a user a single repository for their GTD lists and support materials. The beauty of this implementation is that this exists as a single, portable cross platform file that runs on your computer, so you can access it even when you’re not online.

This is the coolest GTD implementation I’ve seen. Make sure you take a look at this. Oh, and if you havent looked at GTD before, make sure you check it out too.

No Comments

Catching up

It’s been a while since I’ve posted last. The entire team took off to Las Vegas for the VSLive! conference. It was very valuable to have everyone there, because everyone had the same exposure and we were able to have some very engaging conversations over dinner. David had some great posts over at elegantcode.com that talked about things we learned there.

It’s amazing what happens when you’re out of touch for a while. I see that NewsGator bought FeedDemon. This is very exciting, and I want to congratulate both Nick and Greg. There will certainly be some exciting things coming out of this deal.

Martin Gudgin has created some Indigo tutorials. Taking Aaron Skonnard’s Indigo immersion class at VSLive! makes this type of information very interesting. The Pluralsight folks are doing a great job on their blogs over there. If you’re not subscribed yet, make sure you do.

Nikhil Kothari has released a great little browser extension that will make debugging an ASP.NET web app much easier by letting you examine view state, reminding you to turn off debug mode, and showing tracing information. Very cool!

Lastly, the love affair with my SMT5600 continues. Like Scoble, I too find myself fondling this phone. I have ordered a miniSD stick for it that will hopefully show up tomorrow. I’ll need to see how this works out, but Im thinking that I may not buy an ipod because of this device.

Im hoping to get caught up with both my work and personal life and that posts will continue more frequently.

No Comments

Inbound toy: The Scoble Phone

A few months back, I was looking into upgrading my cell phone. The phone that I was looking at was the “Scoble phone” (an Audiovox SMT5600). Unfortunately, ATT was not selling new phones and to get a SmartPhone, I was told I needed to get the Motorola MPx220.

At first, I was quite pleased with this phone, as it was really nice having all of my information with me. However, after having this phone for a while, I’ve come to realize that the MPx220 is a collossal piece of crap. Numerous dropped calls, volume issues, and missing calls. For example, earlier tonight, the phone started to ring. I went to pick it up, and the phone said missed call. When I called the person back, they said the phone rang 8 times (which also means my voice mail didnt pick up).

Thinking that I might have just had a defective phone, I had Cingular ship me a new one, and I’ve also swapped out the SIM chip thinking that it may have been defective. None of this helped, and after looking around online, it seems that Im not the only one having these kinds of problems.

The good news is that Cingular announced yesterday that they would be making the “Scoble phone” available to it’s subscribers. I called last night to tell Cingular that I wanted to return my MPx220 in favor of the SMT5600 (due in large part to the numerous glowing reviews that I’ve read regarding this model). They mentioned that phones are not available typically until 24 hours after the press releases (apparently the computer systems need time to update) and that I should call back in the morning.

To make a long story short, my very own SMT5600 (under Cingular’s branding) should be here before 3:00PM tomorrow (assuming that FedEx delivers on time). Im sure that Ill have much better luck with this one…

1 Comment
flag
Favorite Charity
wounded warrior project
Search
Social
  • mattberther on twitter
  • mattberther on linkedin
Syndication
Archives
  • January 2010
  • September 2009
  • July 2009
  • June 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • September 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004
  • September 2004
  • August 2004
  • July 2004
  • June 2004
  • May 2004
  • April 2004
  • March 2004
  • February 2004
  • January 2004
  • December 2003
  • November 2003
  • October 2003
  • September 2003
  • August 2003
  • July 2003
  • June 2003
  • May 2003
  • April 2003
  • March 2003
mattberther.com © 2003 - 2010