Expert Spring MVC and Web Flow

(Dana P.) #1

These principles are not new, and they have been preached for a long time in the object-
oriented world. Until the arrival of Inversion of Control containers, with strong Dependency
Injection support, these principles were very difficult to implement in medium to large sys-
tems. If you have built systems before and had to throw out many of your hard-learned OOP
practices, you will soon breathe a welcome sigh of relief. The Spring Framework makes it
possible to integrate and develop loosely coupled web application systems.


Summary


We’ve shown that a typical Spring MVC application has many layers. You will write code to
handle the user interface, the web navigation, the service layer, the domain model, and the
persistence layer. Each layer is isolated in such a way to reduce coupling and increase testabil-
ity. The layers use interfaces as their contracts, shielding other layers from implementation
details. This allows the layers to change independent of the rest of the system. The system
becomes more testable, as each layer can be tested in isolation. The other layers are mocked
in the unit tests, keeping test runs quick and focused on testing only the target code.
We’ve also shown that the most important layer is the object model. The object model
contains the business logic of the system. All the other layers play supporting roles and handle
orthogonal system concerns such as persistence or transactions. The web layer is kept thin,
implementing no business logic and providing a bridge between the world of the web and the
object model.
A main goal has been to keep the framework out of our code as much as possible. By using
the Spring Framework, we are able to keep framework-specific code out of our object model
completely. The interfaces to our data access layer are unaware of any framework. The service
façade layer’s interfaces are also devoid of any framework code. The Spring Framework binds
our layers together transparently, without dictating application design or implementation.


CHAPTER 3 ■SPRING MVC APPLICATION ARCHITECTURE 39
Free download pdf