Skip to content

Defensive Design

September 10, 2007

In his most recent article, Joey Beninghove makes an excellent point. He describes creating an additional service layer (which he refers to as the anti-corruption layer) for shielding your application from services with bad APIs. I use this technique constantly, although I generally call it a defensive design layer. It particularly comes in handy when I have to work with WSDL-generated web service proxies. I don’t want that junk leaking through my application, so I generally create my own facade that works the way I expect it to, and translate to the underlying web service as necessary. (This also means I can mock up the web services more easily during development and testing.)

In fact, one of the projects I’m working on right now has a defensive design layer to shield against the API of Microsoft Reporting Services. Kudos to Microsoft for exposing the functionality via a web service, but I really wish they would have spent some more time making the interface logical. Take the “device info” junk that you have to pass to the ReportExecutionService in order to render a report. Extensibility is great, but you’re telling me they couldn’t come up with a better solution than passing an XML string as one of the parameters of the method call? Sheesh.

Relying on a defensive design layer in your application can also protect your application from changes in the underlying service itself. In extreme cases, it can even help you to replace a third-party component with your own custom-rolled one.

About these ads

From → miscellaneous

2 Comments
  1. Just want to make sure folks know that I wasn’t the one who came up with the term Anti-Corruption Layer. It’s one of the techniques that comes out of DDD. :)

  2. @Joey: See, and I was totally trying to give you credit. :)

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: