Java接口/实现命名约定[重复]

本文翻译自:Java Interfaces/Implementation naming convention [duplicate]

This question already has an answer here: 这个问题在这里已有答案:

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值