I work this way (Struts2 + Hibernate):
My Struts Actions is only responsible for show informations on web browser. Not thinking.
User -> Action -> Service -> Repository -> Data Access
Or:
I Want See -> How to see -> What to Do -> How to Get -> Where to get
So, in first layer (the view) I have something like:
public String execute () {
try {
CourseService cs = new CourseService();
Course course = cs.getCourse(idCourse);
} catch (NotFoundException e) {
setMessageText("Course not found.");
} catch (Exception e) {
}
return "ok";
}
As you see, my "view" do not think. It's asking for a service (for manage courses) a specific course. That service can do many things more, like reports, seraches, and so on. The results is always a list or a specific object (like the example).
The services are the real machine, apply rules and access the Repository (to manage the data).
So, if I put my Services, Repositories and DAOS in different libraries, I can use it even in a text-based program, or a Window based desktop system with changing nothing.
The service knows what to do, but does not know how to show.
The view knows how to show, but does not know what to do.
The same with Service / Repository: The service send and request for the data, but does not knows where the data is and how to take it. The repository "make up" the raw data to buisines objects so the Service can work with.
But the Repository does not know anything about the database. The database kind (MySQL, PostgreSQL, ... ) concerns to DAO.
You can change the DAO if you want to change the database and it must not affect the upper layers.
You can change the Repository if you want to update your data management, but this must not affect the DAO and upper layers.
You can change the Services if you want to change your logic, but this must not mess with layers above nor below.
And you can change anything in view, even the technology (web, desktop, text) but this must not implies in touch anything below.
The business logic is Service.
But how to interact with this is to view. What button to show now? Can the user see this link?
Think your system is a console-based program: you must deny if the wrong user choose #> myprogram -CourseService -option=getCourse -idCourse=234
or stop him to press the keys to write this command?
Talking in web-based systems (Struts+JavaEE) I have a separate GUI controller package. In view Action I give the logged user and the class gives me the buttons (or any interface element I want).
<div id="userDetailSubBox">
<c:forEach var="actionButton" items="${actionButtons}" varStatus="id">
${actionButton.buttonCode}
</c:forEach>
</div>
And
private List<ActionButton> actionButtons;
Remember to keep this out from the services. This is VIEW stuff. Keep it in the Struts Actions. Any interface interactions must be fully separate from the real business code, so if you port your system, will be easy to cut what you won't need anymore.