Monday, August 08, 2005

Naming interfaces and classes.

When reading these blogs I started to think about the concept of prefixing interfaces with an I. The I is meant to make it clear to the programmer that it is in fact an interface he is using.

http://www.jnsk.se/weblog/posts/iprefix.htm
http://www.bloglines.com/blog/IngoLundberg?id=5

Prefixing interfaces has, as I see it, two disadvantages: First of all it gives the impression that the interface is a secondary thing, and that there must be a more important class behind it.
When you first see IList you wonder; is there a List as well? The fact is that IList is a List and the I only confuses the user. This leads me to my second point. The unexperiensed programmer might have heard that designing your code with interfaces is a good thing. I have seen programs constructed only using classes, and thereafter added interfaces to all classes with the I prefix. The fact is that interfaces do not make much sense if they are not suppossed to be implemented by more than one class.

1 comment:

  1. Normally I seriously dislike prefixing… (Hungarian notation is send from the enemy of common sense) but when it comes to interfaces I think it makes some kind of sense.

    I se the ‘I’ in interfaces as an indication that this is NOT a class (rather important point), not necessarily a secondary thing. If you are not avare of interfaces you might try to initialize en new IList (yes, I did that).
    But when it comes down to it I se interfaces as a bad excuse for not implementing multible inheritance.

    When it comes to making a one 2 one mapping of a classes to interfaces, this can only be defendet if version compatability issues is the reason and this is rearly the case. ;)

    ReplyDelete