Java – how to organize classes and packages

How do you decide what a package name should be, what classes should enter and what packages?

I'm working on a project where I keep adding / deleting courses instead of really determining whether a new package is needed or should be added to something I don't know now

Do you follow a set of rules when creating a new package?

How do I know if you don't duplicate the packaging function? Is this just familiarity with the project

Any pointer is appreciated

Solution

The course should do one thing (single responsibility principle)

Classes that do related things should be in the same package If you find that you can more closely associate some classes in a package and make them a sub package!

For example, if I have a project of these classes:

> GreetingInputWindow > GreetingDatabaSEObject > GreetingDatabaseConnector

I may just put them all in my greeting bag If I want, I can put the greetinginputwindow in the meeting In the UI package, the other two are placed in the meeting DB package

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>