1

I'm learning MVP patter. In some examples, I saw this! Any one could demonstrate why programmers use this name convention?

tereško
  • 58,060
  • 25
  • 98
  • 150
Milad Khajavi
  • 2,769
  • 9
  • 41
  • 66

3 Answers3

4

Usually I is there to indicate an Interface. Without the I is it a class. Personally I am not a fan of this. I think it is more common in dot net. I havent seen it too much in Java

Reasons why I dislike:

  • IDEs now show icons that indicate whether a class is an interface or not.
  • If I want to change the interface to an abstract class I then have to rename the class
  • It hurts readability.
RNJ
  • 15,272
  • 18
  • 86
  • 131
  • 1) Consider the line of code: `ICollection collection = this.Foo();` You don't have an icon here in IDE. 2) Switching from contract to implementation *is* a breaking change in code (no multiple inheritance) 3) See point 1) – Jakub Konecki Mar 14 '13 at 10:33
  • 1) correct you dont have an icon but do you really care if it is an interface here? 2) agreed it will change the code but why should I have to rename as part of the refactoring. I want to concentrate on compiling and structure then. 3) Have the I there I dont think helps readability. It makes the class name harder to remember IMO – RNJ Mar 14 '13 at 10:36
  • 3) You don't add 'I' to classes - hence the name of class is *not* harder to remember and you avoid confusion what's class and what's interface ;-) – Jakub Konecki Mar 14 '13 at 13:07
1

'I' stands for interface. It's a common naming convention to distinguish interfaces from classes / structures.

Interfaces are not classes - they define behaviour and classes provide implementation.

Read this article on MSDN for more info: Choosing Between Classes and Interfaces

An interface defines the signatures for a set of members that implementers must provide. Interfaces cannot provide implementation details for the members. For example, the ICollection interface defines members related to working with collections. Every class that implements the interface must supply the implementation details for theses members. Classes can implement multiple interfaces.

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
1

It is an artifact from age when Hungarian notation was thought to be a good idea. It lets the user know that the name is for an interface.

Also, it is an extremely stupid practice.

Name of the interface should reflect what sort of contract between classes it signifies. It should not tell you to which class it has been tied to.

It should be class PDF extends Document implements Printable because it lets you know that class implements print() method for some reason (in a real world it would be actually a bad API design, but this is an example) instead of class PDF extends Document implements IDocument .. because this tell you nothing.

tereško
  • 58,060
  • 25
  • 98
  • 150