Package app.messages

At the beginning of this chapter, we decided to put everything inside the app.messages package. Let's take a look at it. Here is everything inside:

AppConfig.java             // Root configuration class
Application.java // Application bootstrap class
AuditingFilter.java // Requests audit Filter
Message.java // Message Entity class
MessageController.java // Message Controller for HTTP API
MessageData.java // Saving message request data structure
MessageRepository.java // Repository class of Message
MessageService.java // Service class of Message
SecurityCheck.java // Security Check annotation
SecurityChecker.java // Security Checker aspect

As you can see, it is a pile of mud. And if we were going to build more features into this app, it would turn into chaos unless we reorganize it.

Let's reorganize it. Since our Messages App is quite small, it would be sufficient to break the app.messages package into subpackages based on the roles of the classes. 

Here is the refactored structure of the app.messages package:

app.messages
/config

/AppConfig.java
/model
/Message.java
/repository
/MessageRepository.java
/service
/MessageService.java
/web
/AuditingFilter.java
/MessageController.java
/MessageData.java
/security
/SecurityCheck.java
/SecurityChecker.java
/Application.java

As you can see, we put all of the configuration classes into an app.messages.config package, the message entity class into an app.messages.model package, and the service and repository classes into their own packages. And since AuditingFilter, MessageController, and MessageData all deal with HTTP requests, they live in the app.messages.web package, while the app.messages.security package is for security-related items. The Application.java bootstrap class stays in the app.message package.

This is a typical structure of a layered application, which usually contains three layers—a web layer, a service layer, and a DAO layer. This type of structure isn't a silver bullet for all applications. We will discuss more about code design later in this book. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.164.75