Tuesday, 19 May 2015

Prefix class with 'I'

The other week I was looking at some code another Delphi developer had written and noticed that he prefixed classes with 'I' instead of 'T'. In my world the prefix 'I' means its an interface, but he argued that an abstract class is an interface and that all abstract classes should be prefixed with 'I'. I disagreed with him for various reasons, one being that Delphi standard classes do not do this.

Does anyone else prefix their abstract classes with 'I' and only use 'T' for concrete classes?  

2 comments:

  1. No - abstract classes are different from interfaces, and your colleague is revealing a lack of understanding. Perhaps he/she comes from a C++ background, where the only way to define an interface is to use an abstract class.

    In Delphi an interface is a different beast to a class without any implementation, ie an abstract class.

    The I prefix always indicates an interface - that is a type declared with the interface keyword - in all code I've ever seen. Relying on that lets you assume that IFoo is an interfaced type, with associated details like reference counting and Supports() support.

    An abstract class is simple a class without implementations and is quite different - a "poor man's interface". Treating an abstract class type as though it was an interface could lead to all sorts of code problems, including leaks, and apart from the confusion this demonstrates this is the main reason you're right and it should not be done.

    ReplyDelete
  2. Yes the person does come from a C background, he is also stubborn and believes he is right. I will just have to keep and eye when looking at any code he does.

    I think the company should implement code guidelines agreed by the developers, this make it clear that interfaces only should be prefixed with an 'I' and would solve the issue.

    ReplyDelete