Question

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

Was it helpful?

Solution

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.

OTHER TIPS

'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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top