The Artima Developer Community
Sponsored Link

Java Buzz Forum
IAdapterAdapter - naming patterns run amok

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Norman Richards

Posts: 396
Nickname: orb
Registered: Jun, 2003

Norman Richards is co-author of XDoclet in Action
IAdapterAdapter - naming patterns run amok Posted: Dec 30, 2003 1:40 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Norman Richards.
Original Post: IAdapterAdapter - naming patterns run amok
Feed Title: Orb [norman richards]
Feed URL: http://members.capmac.org/~orb/blog.cgi/tech/java?flav=rss
Feed Description: Monkey number 312,978,199
Latest Java Buzz Posts
Latest Java Buzz Posts by Norman Richards
Latest Posts From Orb [norman richards]

Advertisement

In theory naming patterns are supposed to aid in understanding the function of a class. Unfortunately, this isn't always the case. With poorly selecting naming patterns, the results can be quite comical. Take for example (from a real project) the IAdapterAdapter.java.

What is an IAdapterAdapter, you ask? Well, in this system there is a concept of an Adapter. What it specifically does isn't important, it might as well be a Frobnotizer, in which case we'd have an IFrobnotizerAdapter. It was realized that there may be many things that need to be adapted (frobnotized) and that there wouldn't be a single implmentation. In fact, most likely it would be another existing component that wanted to do the adapting (frobnotizing). Nodding to the adapter pattern, an AdapterAdapter class was made to provide some base functionality useful for adding to components that needed adapter (frobnotizer) functionality. Being good coders we know that it's better to work with an interface, and decided that our FrobnotizerAdapter, er.. AdapterAdapter, needs an interface, which is kindly marked with vaguely Hungarian I becoming an IAdapterAdapter. It's really quite obvious, isn't it?

What's wrong here? There are several big problems. Let's start with the base name - Adapter. Even if you never thought you would need to adapt an adapter, it's a poor name because it conflicts with your naming convention for (non-frobnotizing) adapters. I don't much care for the adapter naming convention here, primarily because it's not really an adapter. If you are going to name something after a design pattern, you should at least pick one that matches.

Finally, there is that dreaded ISomethingOrOther convention for interfaces. I can't figure out why people think this is clever. I follow the principal of least adornment, which suggests that the most external class should have the least adorned name. Why? The base name is what we focus on. When you see IColor, you think "Color". In your code, you will want to work with Color objects and will try gravitate towards that instead of the IColor interface you want people to focus on. The interface should be the focus and the class is just an implementation detail. The implementing class should really should warn people away. I think the Impl convention is nice, at least in this respect. A class named ColorImpl might as well have a big "No Soliciting" sign on it. Anyone knocking is probably doing so for a reason.

The moral here is to be careful with your naming conventions. Try and choose good ones, but be willing to admit when they are breaking down. Like coding conventions, they are general guidelines and not hard rules. I know many people will disagree with me on this point and insist that coding conventions are the only thing standing between the code and complete chaos. But I don't mind bending the rules a bit when they are doing more harm than good.

Read: IAdapterAdapter - naming patterns run amok

Topic: Tog on security Previous Topic   Next Topic Topic: PATROL Express 3.0 Award PR:

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use