Yesterday , i was reading Clean Code by Uncle Bob. While i was doing so , i came across a line that really stuck my thought patterns and i would like to share it with my readers as well.
The line looks something like, provided that there is a shape factory that will be implemented by concrete classes.
“What should you name them? IShapeFactory and
ShapeFactory? I prefer to leave interfaces unadorned. The preceding I, so common in
today’s legacy wads, is a distraction at best and too much information at worst
So if I must encode either the interface or the implementation, I choose
the implementation. Calling it ShapeFactoryImp, or even the hideous CShapeFactory, is preferable
to encoding the interface.”
This is true, in a sense today even our popular refactoring tools [there are not much, so you can easily figure out] when typed, precedes the interface with “I” word. And if we look though all the open source foundries, we will see this here and there with no exception. Even honestly, i encode interfaces with “I” word, but technically it would be much better if we have a structure like
After, reading that i came to realization that we should abandon this “I” encoding for interfaces that is going on decades to devs after devs. There should be a “General coding guidelines” which should include it and FxCorp should mark it as invalid during code analysis.
Now, did i say something wrong , enlighten me, why we still need to encode our inferface, when our modern compiler are smarter enough to do it for us. I guess we are way too ahead from the days of integer based type encodings , aren't we ?
[Edit : This is true that starting an interface with “I” has become more of a convention today. [SA1302: InterfaceNamesMustBeginWithI]. There are numerous project that follows it even i don't remember, i wrote one without it, at the same time the words at the book still worth thinking along with meaningful names as stated [From book] “I don’t want my users knowing that I’m handing them an interface. I just want them to know that it’s a ShapeFactory.” Also, there are comments like, “I like “I” because i want to know that its an interface, but question remains what productivity it will really provide?. Finally, convention is important to make us feel right at home but its not bad to discuss on other options that are forwarded by an industry expert, i mean there must be a reason.]
[Edit: The title should rather be why you should use “I” in your interface just because it’s a convention or you are used to it, what if you don’t use it , is there other options and are they worthy ? ]