To use the 'I' prefix for interfaces or not to

前端 未结 20 1838
长情又很酷
长情又很酷 2021-02-01 02:54

That is the question? So how big a sin is it not to use this convention when developing a c# project? This convention is widely used in the .NET class library. However, I am not

20条回答
  •  甜味超标
    2021-02-01 03:49

    In my opinion the biggest reason "I" is often prefixed is that the IDEs for both Java (Eclipse) and .NET (V Studio) do not make it extremely clear that the Class you are looking at is in fact an interface. The package browser in eclipse shows the same icon till you expand the class file and the font of an Interface declaration is not any different than a class.

    An Example would be if I type:

    ISomeInterface s = factory.create();
    

    ISomeInterface should atleast have some sort of font modification to show that its an interface (like italics or underline).

    The other big reason is in the Java world that people prefix with "I" is that it makes it easier in Eclipse to do a "Ctrl-Shift-R" and search for only interfaces.

    This is important in the Java/Spring world where you need interfaces as your collaborators if you plan on using any AOP magic or some other Dynamic proxies.

    Than you have the nasty choice of either prefixing your interface with "I" or suffixing your implementation class with "Impl" like ListImpl. I abhor the suffixing of classes with "Impl" to make the interface and concrete differ in name and prefix the prefix of "I".

    In general I try to avoid making lots of interfaces.

    In my own code I would never prefix with "I". I'm only give some reasons why people do it which is for old code consistency.

提交回复
热议问题