The code of this app should be extended by
adding some CSS styling for the user interface pages and
adding constraint validation.
We show how to do this in the follow-up tutorial Building Java Web Apps Tutorial Part 2: Adding Constraint Validation.
We briefly discuss further points of attention.
Any damn fool can write code that a computer can understand, the trick is to write code that humans can understand. (Martin Fowler in After the Program Runs)
Code is often "unnecessarily complicated, convoluted, disorganized, and stitched together with disdain", as observed in a post by Santiago L. Valdarrama who recommends using comments when necessary, only to explain things that can't be made clear enough, but rather make your code reveal its intention through the use of better names, proper structure, and correct spacing and indentation.
Another issue with the code of this Java example app is the repetitious boilerplate code needed per entity class for the storage management
methods add
, retrieve
, update
and destroy
,
and their wrappers in the corresponding controller classes. While it may be instructive to write
this code a few times for learning app development, you don't want to write it again and again
later when you work on real projects.
It is desirable that a web app can still be used when the user is offline. However, this is not possible in the case of a back-end application architecture as implied by JSF.
One of the most fundamental principles of software architecture is separation of concerns. This principle is also the basis of the Model-View-Controller (MVC) architecture paradigm. It requires to keep the different functional parts of a software application independent of each other as much as possible. More specifically, it implies to keep the app's model classes independent of
the user interface (UI) code because it should be possible to re-use the same model classes with different UI technologies;
the storage management code because it should be possible to re-use the same model classes with different storage technologies.
In this tutorial, we have kept the model class Book
independent of the UI
code, since it does not contain any references to UI elements, nor does it invoke any view
method. However, for simplicity, we didn't keep it independent of storage management code, since
we have used JPA annotations, which bind the class to JPA object-to-storage mapping technology,
and we have included the method definitions for add, update, destroy, etc., which invoke the
storage management methods of a JPA environment's entity manager. Therefore, the separation of
concerns is incomplete in our minimal example app.
We will show in a follow-up tutorial how to achieve a more complete separation of concerns.