What is the rationale behind this naming convention?
I don\'t see any benefit. The extra prefix just pollutes the API.
My thinking is inline with Konrad\'s respo
I also like it cause I can read it as "I verb-behavior" as in "ICanSave" or "IDoDoubleEntry" etc...
Firstly I believe prefixing with I then description is wrong because it means implementations can have a shorter name. IList (intf) -> List. This is an anti-pattern as we all know we should be using intf and probably only concrete types when creating. Don't flame me this is a generalization but the premise is intf only impl rarely. The implementation name should describe how it's implementing the intf or what it's doing. Think intf List, LinkedList which implements List using a linked list. Who cares if it's longer as we should be using List most of the time. If we have a class implementing many intf we probably should not include all the intf as the shadows the real purpose of the class. IN the case something removed without the intf makes sense. Eg ppl call me by name not Person, Sibling, developer etc using my name is the best most descriptive name. I suppose if a class is impl a simple intf then call it Default Intf which makes it on ious this is the default implementation of Intf. Names of classes sHould in the end be human readable and almost a short phrase describing their purpose. Prefix codes etc are not great as we communicate with words not codes. Computers do t cAre what classes are called so why remains is that we name things so the names help us and our colleagues.
I always thought it was fun to use verbs for behavioral interfaces. This is a departure from the class naming convention of using nouns, but it allows the class to "speak" to its behavior.
class Dog: IBark
This does not work well for structural interfaces like WCF interfaces, but we don't need to have fun all the time.
to answer your question, think of the I
as "implements" So...
class DogDataService : Dog, IDataService
this service class inherits from Dog
and implements IDataService
I'm still not really answering your question, but the I
is useful because you get naming collisions between namespace, class and interface.
namespace DataService
interface DataService
class DataService: DataService
so we end up with
namespace DataServices
interface IDataService
class DataService : IDataService
I think in reality, it's a sanity convention.
With all of the arguments about naming conventions and giving proper names to variables and methods that actually describe what they do...why not just name your interfaces (e.g. PetInterface, PlayerInterface, etc.) and do away with the prefix "I" all together. So what you have to type an additional 9 letters, at least the "I" is removed and we know it is not a class, because it says "Interface".
Its the complete opposite, the naming convention clearly identifies an interface.
For example if you have:
public class Dog : IPet, IMammal
{
....
Just from reading it, I can safely assume that IPet and IMammal are probably interfaces.
The .NET CLR allows for single class inheritance. So, if I have a base class..I can only inherit one class from it. Lets change the IPet interface to a base class..our example now becomes
public class Dog : Pet, IMammal
{
....
I am inheriting from the Pet class and implementing the IMammal interface.
If we did it what you are suggesting and removed the letter "I" we have this:
public class Dog : Pet, Mammal
{
....
Which one is the class I am inheriting from? Which is the interface I am implementing? It gets confusing right? (FYI..you are supposed to put the base class always first, so you could argue that point...but if you are arguing to remove the letter I from prefixing interface names I doubt you follow that practice as well)
As you can see that naming convention easily tells me a lot about my object without me having to investigate further. I can easily see what I am inheriting vs what I am implementing.
I think that the IInterface naming convention is silly. It's an example of Hungarian notation, and I subscribe to the school of thought that despises Hungarian notation. If you have an interface with only one implementation that has the same name, consider the possibility that this is a code smell.
However, I still use it, because in this case IInterface is recommended by Microsoft, and "standard is better than better".