What is the Java naming convention for list of objects which have plural forms ending with "ies" or non-standard "s" plural forms?

huangapple go评论68阅读模式
英文:

What is the Java naming convention for list of objects which have plural forms ending with "ies" or non-standard "s" plural forms?

问题

我找不到涵盖不遵循标准“s”复数形式的单词用法的Java命名约定。

//给定一列生物,getter方法应该是什么?

private List<Biology> biologies;

public Biology getBiology();
public List<Biology> getBiologies();

当复数形式差异很大时,约定是什么?

//给定一列章鱼,getter方法应该是什么?

private List<Octopus> octopi;

public Octopus getOctopus();
public List<Octopus> getOctopi();
英文:

I am unable to find any naming conventions for Java that covers the usage of words that does not follow the standard "s" plural form.

//Given a list of biologies, what should the getter method be?

private List&lt;Biology&gt; biologies;

public Biology getBiology();
public List&lt;Biology&gt; getBiologies();

What is the convention when the plural form is much different?

//Given a list of octopi, what should the getter method be?

private List&lt;Octopus&gt; octopi;

public Octopus getOctopus();
public List&lt;Octopus&gt; getOctopi();

答案1

得分: 5

这只是一个意见的边缘,但我称之为“最佳实践”并说:

使用复数形式并且拼写正确。

就像你应该拼写所有的变量/字段正确一样(如果清楚的话,长术语的缩写是可以接受的,例如 minmax等)。


不具有权威性,但Intellij会自动生成拼写正确的复数形式,例如:

List&lt;Company&gt; x; // 重命名为“x”后会自动建议“companies”
英文:

This is on the edge of opinion, but I'm calling "best practice" and saying:

Use plurals and spell them correctly.

Just as you should spell all variables/fields correctly (abbrevations of long terms being acceptable if clear, eg min, max etc).


Not authorative, but Intellij auto-generates correctly spelled plurals, eg:

List&lt;Company&gt; x; // &quot;companies&quot; will be auto-suggested if you rename &quot;x&quot;

huangapple
  • 本文由 发表于 2020年9月1日 07:43:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/63679528.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定