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.
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.
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… :)
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.
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.
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…


