我应该给出什么名称作为项目名称、包名称、类名称 - (java - eclipse)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1886495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 23:33:54  来源:igfitidea点击:

what names should I give as project name, package name, class name - (java - eclipse )

javaeclipse

提问by silverkid

I have never understood what is the ideal way to name a project, package, class. I do it in a random way which doesn't look professional at all. I know the class name should start with a capital alphabet. But what I don't really have trouble with is finding the names that are suitable and look professional. lets consider this example. If I am writing a program for fibonacci series i give names like this:

我一直不明白什么是命名项目、包、类的理想方式。我以一种看起来一点也不专业的随机方式来做。我知道班级名称应该以大写字母开头。但我并没有真正遇到麻烦的是找到合适且看起来很专业的名字。让我们考虑这个例子。如果我正在为斐波那契数列编写程序,我会给出如下名称:

project name = fibonacci_project
package name = org.fib.code1
class name = Code1

Doesn't look neat right? How would you do it ?

看起来不整齐吧?你会怎么做?

采纳答案by Hyman

There are some tips about naming:

关于命名有一些提示:

  1. As you said classnamehave the capitalization of first letter of every word, eg. LongClassName
  2. Sun always preferred long names that explain clearly the meaning of the class (think about DefaultTableModel). Code1is definetely not right, maybe FibonacciCalcor something that contains Fibonacciwould fit better.
  3. Preprend Abstractif it's an abstract class
  4. Append Implif it's an implementation of a particular interface
  5. Package names should start with org, com, it, etc (usually it was the backward URL of project repository or the nick of the coder)
  6. You should split your packages according to functionality, your example is really simple so there is not a way to do it.
  1. 正如您所说,classname的每个单词的第一个字母都大写,例如。LongClassName
  2. Sun 总是喜欢能清楚地解释类含义的长名称(想想DefaultTableModel)。肯定Code1是不对的,也许FibonacciCalc或者包含的东西Fibonacci更适合。
  3. Abstract如果它是一个抽象类,请预先准备
  4. Impl如果它是特定接口的实现,则附加
  5. 包名应以 org、com、it 等开头(通常是项目存储库的后向 URL 或编码器的昵称)
  6. 您应该根据功能拆分包,您的示例非常简单,因此没有办法做到这一点。

Think about something more complex in which you have:

想想你拥有的更复杂的东西:

org.package.gui
org.package.core
org.package.extensions

回答by ChssPly76

For starters, it's Fibonacci.

首先,它是Fibonacci

See Sun's java naming conventionsfor some details on package / class names.

有关包/类名称的详细信息,请参阅Sun 的 java 命名约定

Aside from that, the general rule of thumb is - all your names should be descriptive:

除此之外,一般的经验法则是 - 你的所有名字都应该是描述性的:

  • for class - what does it do (or what does it represent)
  • for package - what common functionality (goal) do all classes within that package provide (aim to achieve)
  • for class - 它做什么(或它代表什么)
  • 对于包 - 该包中的所有类都提供哪些通用功能(目标)(旨在实现)

回答by cherouvim

Your project name could be "fibonacci solver".
Your package could start by "com.silverkid.fibsolver"
Your main class would be "FibonacciSolver.java"

您的项目名称可以是“斐波那契求解器”。
您的包可以以“com.silverkid.fibsolver”开头
您的主类将是“FibonacciSolver.java”

回答by Alberto Zaccagni

Examples:

例子:

Project name - FibonacciSeriesProducer
Package name - com.lazywithclass.utils, com.lazywithclass.entryPoint
Class name - FibonacciLogic.java, FibonacciPrinter.java

项目名称 - FibonacciSeriesProducer
包名称 - com.lazywithclass.utils, com.lazywithclass.entryPoint
类名称 - FibonacciLogic.java, FibonacciPrinter.java

This is how I would have done it, maybe during development this will change a bit, the really important convention is naming convention for class names, see if this steps are of some help:

这就是我的做法,也许在开发过程中这会有所改变,真正重要的约定是类名的命名约定,看看这些步骤是否有帮助:

  1. identifiy objects that you will need to solve the problem
  2. Knowing what one class' purpose will be name it accordingly
  3. Keep an eye on your class names, mantain them meaningful through the development
  1. 确定解决问题所需的对象
  2. 知道一个班级的目的是什么,相应地命名它
  3. 注意你的类名,在开发过程中保持它们的意义

See herefor some examples.

有关一些示例,请参见此处

回答by zedoo

I like the eclipse project naming scheme, where a project name is simply the name of the core package that the project provides, e.g. Project name: org.eclipse.emf.core or org.eclipse.emf.common

我喜欢 eclipse 项目命名方案,其中项目名称只是项目提供的核心包的名称,例如项目名称:org.eclipse.emf.core 或 org.eclipse.emf.common

回答by Vinit Kumar

Your class name should always start with Uppercase. your package name should always start with lowercase. and your method name inside the class should also start with the lowercase.

您的类名应始终以大写开头。您的包名应始终以小写开头。并且您在类中的方法名称也应以小写字母开头。