what names should I give as project name, package name, class name - (java - eclipse )
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 开发者_C百科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 ?
There are some tips about naming:
- As you said classname have the capitalization of first letter of every word, eg.
LongClassName
- Sun always preferred long names that explain clearly the meaning of the class (think about
DefaultTableModel
).Code1
is definetely not right, maybeFibonacciCalc
or something that containsFibonacci
would fit better. - Preprend
Abstract
if it's an abstract class - Append
Impl
if it's an implementation of a particular interface - Package names should start with org, com, it, etc (usually it was the backward URL of project repository or the nick of the coder)
- You should split your packages according to functionality, your example is really simple so there is not a way to do it.
Think about something more complex in which you have:
org.package.gui
org.package.core
org.package.extensions
For starters, it's Fibonacci.
See Sun's java naming conventions for some details on package / class names.
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)
Your project name could be "fibonacci solver".
Your package could start by "com.silverkid.fibsolver"
Your main class would be "FibonacciSolver.java"
Examples:
Project name - FibonacciSeriesProducer
Package name - com.lazywithclass.utils, com.lazywithclass.entryPoint
Class name - 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:
- identifiy objects that you will need to solve the problem
- Knowing what one class' purpose will be name it accordingly
- Keep an eye on your class names, mantain them meaningful through the development
See here for some examples.
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
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.
精彩评论