0

I have been provided with a Java Application on which to apply the Three-Tier architectural style; One of the use cases to do is the login. I've studied all the theory and rules that apply to this architectural style, but I need to understand the logic of the objects co-operation between the various levels and how patterns work together on each level to realize this (and the others) use case.

First, I've created the three basical packages: Presentation, Application and Data. In addition, I included one more package about the Boundary classes, The various GUIs from which requests will be sent.

In the Presentation layer, I just put a Front Controller, that encapsulates the presentation logic required by clients using the application.

In the Data layer, I put a DatabaseConnection class (Class that communicates with the database and that is responsible for loading the driver, connecting to the database, querying etc.) and DAOs classes (Data Access Object, that interfaces with the database).

The real problem is that I don't know what to put in the Application level, which represents the main part of the application, defining the domain model of the application, that is: their entities, their relationships, and application logic. It should not contain any reference to how the data will be presented to the user or how they will be saved.

So, I currently have this hierarchy:

Main ---> Boundary > Presentation > Application > Data > Database

In accordance with this architecture, how can I make a simple login? Bearing in mind that each level can communicate ONLY with the underlying level; For example, a class in Boundary layer cannot comunicate directly with a class in Data layer, Boundary's classes can comunicate with Presentation's classes only. If necessary, you can post a pseudocode, which makes the idea of the steps to do.

Zoythrus
  • 165
  • 1
  • 11

1 Answers1

1

Your Boundary calls only basic methods on the Presentationlayer.

Let's say the User clicks a Button to create a User the flow would be the following: Boundary calls method createUser(String name, int age) on the FrontController (Presentationlayer). The Controller can check some basic (UI-Related) things and would then call a similar method on the Applicationlayer.

The Applicationlayer can now process some further checks (for example: is the Current Active User allowed to create a User?). The Applicationlayer takes the given informationen (name and age), creates a DAO based on that and invokes the method to create the User on the Datalayer (DAO).

The Datalayer simply inserts the given information.

Felix
  • 2,256
  • 2
  • 15
  • 35
  • Your comment has been helpful, but I would like something more rigorous. So, using the same logic, I wanna do a login. I've the boundary of the login class, called *B_Login* with two textarea and one button. When I press the button, I send a request to the FrontController that loads the driver, set the connection and calls the method dispatch(String request, Arraylist params); then? What happen between the Application layer and the Data layer? For example, if in the Application layer I've a Business Object, Transfer Object or Application Service, How do I keep logging in? – Zoythrus Jul 02 '17 at 00:53
  • 1
    The Connection should not be set in the FrontController. Such an information is too specific and belongs in the Applicationlayer or even Datalayer. The Applicationlayer should check if the given Values (Username and Password) are valid (for example an empty String could already rejected here, without even really trying to Login). – Felix Jul 02 '17 at 01:02
  • Thank you very much about these tips, I will try to follow them accurately. – Zoythrus Jul 02 '17 at 01:09
  • You're welcome. I hope I didn't say something wrong, if someone sees my answer and thinks I told something wrong feel free to tell me or add an answer. – Felix Jul 02 '17 at 01:13
  • Just a little clarification: as I said, I created two Packages: Boundary and Presentation, just to put some order between the views and the requests handled by the Front Controller. Now, if I wanna do a login, as we said, I call the method dispatch(String request, Arraylist params), the question is: Could I declare, in the boundary, a LoginTO? Because Transfer Objects are in the Application layer and they just trasports data between the Presentation and the Integration Tier; just because I could have put the boundaries inside the Presentation package, but, as I said, I wanted to put order. – Zoythrus Jul 02 '17 at 16:23
  • 1
    For me the Boundary and the FrontController are both part of the Presentation, so it is ok to use Parts of the Applicationlayer (or, like to TO something thats between those two) in the Boundary. – Felix Jul 02 '17 at 16:49
  • Well done, so if I want to check that there are no empty fields in the textareas, who deals this control? The Business Object class? In according to the architectural style, would it be wrong to do something like this in the boundary ActionPerformed method? if(jTextFieldLogin.getText().equalsIgnoreCase("") || jTextFieldPassword.getText().equalsIgnoreCase("")) { JOptionPane.showMessageDialog(null, "compile both textareas"); } – Zoythrus Jul 02 '17 at 18:02
  • What is the best choice? Control in the boundary (with the code I wrote in the last comment) or control in the Application Layer by using a LoginBusinessObject? – Zoythrus Jul 02 '17 at 18:10
  • 1
    An empty Check can be done in the boundary, but nothing more specific. Example if it was a registration: Boundary checks if typed Email is possibly an email, application layer checks if that email is already registered – Felix Jul 02 '17 at 18:24
  • https://www.tutorialspoint.com/design_pattern/front_controller_pattern.htm What do you think about this kind of Front Controller? How can I modify it? – Zoythrus Jul 02 '17 at 19:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/148182/discussion-between-rollback-and-zoythrus). – Felix Jul 02 '17 at 20:44
  • Ok, I'm waiting for you – Zoythrus Jul 03 '17 at 14:58
  • I've a few doubts that I would like to clarify as soon as possible. I'm sorry to bother you all the time, but with this architectural style I'm a beginner. Regarding the login use case only: I've declared a LoginTO in the Boundary of Login. I filled it with username & password and I send (The LoginTO) to the FrontController. Then, if I haven't Business classes about the login, How can I resolve it? Because I cannot declare a DAO in the Boundary. – Zoythrus Jul 04 '17 at 00:29