本文翻译自:Java Interfaces/Implementation naming convention [duplicate]
This question already has an answer here: 这个问题在这里已有答案:
- Interface naming in Java [closed] 11 answers Java中的接口命名[关闭] 11个答案
How do you name different classes / interfaces you create? 如何命名您创建的不同类/接口? Sometimes I don't have implementation information to add to the implementation name - like interface FileHandler
and class SqlFileHandler
. 有时我没有添加到实现名称的实现信息 - 比如接口FileHandler
和类SqlFileHandler
。
When this happens I usually name the interface in the "normal" name, like Truck
and name the actual class TruckClass
. 当发生这种情况时,我通常将该界面命名为“普通”名称,例如Truck
并命名实际的类TruckClass
。
How do you name interfaces and classes in this regard? 在这方面,您如何命名接口和类?
#1楼
参考:https://stackoom.com/question/BoG5/Java接口-实现命名约定-重复
#2楼
The standard C# convention, which works well enough in Java too, is to prefix all interfaces with an I
- so your file handler interface will be IFileHandler
and your truck interface will be ITruck
. 标准的C#约定,在Java中运行良好,是为所有接口添加一个I
- 所以你的文件处理程序接口将是IFileHandler
,你的卡车接口将是ITruck
。 It's consistent, and makes it easy to tell interfaces from classes. 它是一致的,并且可以很容易地从类中分辨出接口。
#3楼
Some people don't like this, and it's more of a .NET convention than Java, but you can name your interfaces with a capital I prefix, for example: 有些人不喜欢这样,它更像是.NET约定而不是Java,但你可以用大写字母I来命名你的接口,例如:
IProductRepository - interface
ProductRepository, SqlProductRepository, e