Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to build a java program for user login but I am not sure if my MVC design is accurate. I have the following classes:

  • LoginControl - servlet
  • LoginBean - data holder java class with private variables getters and setters
  • LoginDAO - concrete java class where I am running my SQL queries and doing rest of the logical work.
  • Connection class - java class just to connect to the database
  • view - jsp to display the results
  • html - used for form

Is this how you design a java program based on MVC design pattern? Please provide some suggestions?

share|improve this question

closed as too broad by gnat, GlenH7, MichaelT, Ampt, BЈовић Jun 4 at 7:03

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

    
I think this is just a simple 3 layered architecture, but I am not an expert of the topic. As far as I know MVC is not so useful by distributed applications like this, only by desktop applications, or by writing single page javascript GUIs. –  inf3rno Jun 1 at 6:14
1  
The Wiki article Multitier architecture have good explanation for you. Also I suggest you use the Spring MVC for mechanism that allows you to create RESTful Web sites and applications. –  Dozortsev Anton Jun 1 at 9:25
    
@inf3rno MVC is used for web applications, too, exactly as it is used for desktop applications. Of course, MVC is only used for the presentation layer of web applications. –  SJuan76 Jun 1 at 23:23
    
If you have a DAO, ignore the Connection class for the part of MVC. From the MVC view, you just access the DAO for the persistence operations. The fact that the DAO internally uses a Connection class (or not) is an "implementation detail" of the DAO. –  SJuan76 Jun 1 at 23:25
    
@SJuan76 stackoverflow.com/questions/2894597/… You use MVC by web applications in a different way, because the communication between the presentation and the business logic is HTTP. HTTP is stateless and not stateful, so it splits the original desktop MVC into a server side MVC and a client side MVC. This is NOT exactly the same as you would have in desktop... But sure, it is useful by web applications too, in a different way. –  inf3rno Jun 2 at 5:14
add comment

2 Answers 2

Well, you seem to be going on the right direction:

  1. Login Bean you are creating with getters and setters is the Model

  2. View using JSP and HTML - which is great.

  3. Login Control Servlet as the Controller which is perfect as well.

Since you already have mandatory three parts Model, View and Controllers thus you are already following MVC pattern.

For database related stuffs, you probably want to look at Data Access Object Pattern, as you have already created the DAO class. Make the DAO an interface and then a DAOImpl to implement that DAO interface.

Interface: DAO

public interface LoginDao { ...
                         // put method definitions here
                     ..}

Implementation: DAOImpl

public class LoginDAOImpl implements LoginDao { ....
                    // put implementation of methods defined in dao class above here
                     ..}

I hope it helps !! :)

share|improve this answer
add comment

I would do something like

App/Core/Service/DBaseAdapterUI.java Interface, Outlines the methods you need to communicate with the database

App/Core/Service/DBaseAdapter.java Domain Model implementing the interface - using the main database class that you built

App/Core/Mappers/DBaseAdapterMap.java Communicates / transfers the data between the data model to the database... maps the service

App/Core/User.java User class

App/MVC/Controllers/appController.java Controls the app

App/MVC/Models/user.java process the basic - domain layer - basically preparing things for the database adapter

-- continue what you have

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.