« JSPWiki-based Wiki... | Main | re: Rise of the... »

The Coat-of-paint anti-pattern.

Developing a wrapper class or API can be a way to add value to an existing API and can also be a way to isolate an existing API. Wrappers can be very useful, but when applied incorrecly, wrappers can be counter-productive and downright irritating. For example: the Coat-of-paint anti-pattern.

In this anti-pattern the developer wishes to isolate an API behind a wrapper, so he develops a very thin wrapper class for each of the classes in the API. Next, he procedes to use these wrapper classes throughout his code, but because the wrappers are so thin, his code still depends on the concepts, relationships, and often the method signatures of the wrapped API. The wrapper is like a coat-of-paint on the wrapped API, it changes the appearance of the wrapped API but does not truly isolate it.

A better approach would be for the developer to divide his code up into modules or "tiers," with each module having a well defined interface. Instead of isolating the API he wishes to hide behind a thin wrapper, the developer should have isolated the API by using it in only one of his modules.

UPDATE: Another, possibly more difficult, approach would be to develop an abstraction layer over the API that is to be isolated. If you will enventually need to switch out the wrapped API for some other API, then an abstraction layer is the way to go. It is a more difficult approach because, unless the underlying APIs are simple, developing a good abstraction over them can be a challenge.

Comments:

Dave I have to say I disagree or don't understand your AntiPattern. I have posted on my blog how I successfully used the "wrapper API" pattern in my current project. Here is a link to the article http://www.duska.com/blojsom/blog/java/?permalink=DABD42FC555312E5C2EC9F76E7CA6504.txt

Posted by Jeff Duska on May 29, 2003 at 05:30 PM EDT #

Here is what I posted on Jeff's blog to clarify this: I admit, there is a fine line between the coat-of-paint anti-pattern and a good abstraction layer, which is what you describe. For something simple, like your FTP example, developing an abstraction layer is fairly easy. In the coat-of-paint anti-pattern, the abstraction is too thin and exposes too much of the wrapped API, making it very difficult to switch out the wrapped API for something different.

Posted by Dave Johnson on May 29, 2003 at 05:37 PM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed

« JSPWiki-based Wiki... | Main | re: Rise of the... »

Welcome

This is just one entry in the weblog Blogging Roller. You may want to visit the main page of the weblog

Related entries

Below are the most recent entries in the category Java, some may be related to this entry.