Thufir
Thufir

Reputation: 8497

what would be a better packaging and naming arrangement?

Just wondering about naming and packaging conventions for:

thufir@dur:~/NetBeansProjects/USENET$ 
thufir@dur:~/NetBeansProjects/USENET$ tree src/
src/
├── META-INF
│   └── persistence.xml
├── net
│   └── bounceme
│       └── dur
│           └── usenet
│               ├── controller
│               │   ├── CommentsDefaultListModel.java
│               │   ├── GroupDefaultListModel.java
│               │   ├── MessageBean.java
│               │   └── MessagesDefaultListModel.java
│               ├── model
│               │   ├── Articles.java
│               │   ├── NewsgroupsArticles.java
│               │   ├── Newsgroups.java
│               │   ├── PropertiesReader.java
│               │   └── Usenet.java
│               └── swing
│                   ├── Comments.form
│                   ├── Comments.java
│                   ├── Groups.form
│                   ├── Groups.java
│                   ├── MainFrame.form
│                   ├── MainFrame.java
│                   ├── Messages.form
│                   ├── Messages.java
│                   ├── PanelWithTabs.form
│                   └── PanelWithTabs.java
└── usenet.properties

8 directories, 21 files
thufir@dur:~/NetBeansProjects/USENET$ 

In the swing package I put Swing GUI classes, except for "model" type Swing classes. They seem kinda different from JPane's, so I put the MessagesDefaultListModel into the controller package, because it's not really a model, per se, at least to my thinking, because it grabs data from the "model" package. So, even though MessagesDefaultListModel is a model for a JList, I see it more as a controller.

Newsgroups, Articles and NewsgroupsArticles are @Entity classes, so I put them into the model package. These entities correspond with tables newsgroups, articles and newsgroups_articles.

Is this a sane packaging and naming?

Upvotes: 2

Views: 127

Answers (1)

JB Nizet
JB Nizet

Reputation: 692073

I usually prefer having a first functional-level segregation, and then, inside a functional domain, having a second technical segregation.

I would name the model package domain instead. An it feels very strange to have classes named model in a controller package. These are models in the swing MVC architecture, not controllers.

Also, I hate putting anything in the root package. Why don't you put the properties file in a package, the same as the class whhose responsibility is to parse and hold the properties?

Your entities should have a singular name, not a plural name. This is probably the most important refactoring I see: an instance of Articles is one article, so the class should be named Article, not Articles.

Finally, I see entities, I see presentation-related classes, but I don't see any service and data access layer. Data access should not be done in the presentation layer. That's not its responsibility. And you need a place where transactions are demarcated (preferrably in a declarative way): that should be the service layer. A dependency injection framework like Spring hugely helps here, and makes code easily testable.

Upvotes: 2

Related Questions