MVC Best Practices on Java or C#?
-
I need help understanding the best practices of MVC architecture implementation. I'm a Java and C# programmer. I know the basic of MVC. But i'm sorta confused on how to implement it. I know how to make a simple MVC based calculator. But here's the thing. I wanted to make a simple database editor application using MVC. Should I construct a model and controller for every rows (objects) of the table? If so, how about the view of every objects? How do i handle them being deleted, updated, and inserted. And should I make the model and controller for the editor which is also a view. Please help me @_@.
-
Answer:
I typically make a model for what is in the table. In the Java web application world the JSP would be the view and servlet would be the controller. The model would be the beans and data access objects you may store and retrieve the data. For example, if you want to edit an item with an ID in the database of 372: The request might be: /EditItem?id=372 EditItem is a servlet. It uses a DAO that handles the database access and returns. // Create DAO ItemDAO dao = new ItemDAO(); // Get item bean from ItemDAO by passing in ID from request parameter Item item = dao.getItem(request.getParameter("id")); // Put bean on request scope for use by JSP request.setAttribute("item", item); // Then include JSP for display RequestDispatcher rd = getServletContext().getRequestDispatcher… rd.include(request, response); ------------------------ In the JSP you use the bean stored as a request attribute with the name "item" to get the current values. Basically the JSP handles the display and user interface functions. The servlet acts as the controller and delegates to other objects to get the resources needed to fulfill the request. The bean and DAO handle the model aspect to handle the data. This way if you ever decided to switch from a DBMS system to store your data to an LDAP system for instance, you just have to change the DAO in the model layer without having to recode your JSP or servlet because they don't care where or how the data is stored.
Itsme at Yahoo! Answers Visit the source
Related Q & A:
- Where To Get Best AntiVirus For Java Mobile?Best solution by antivirus.com
- How to call java from c#?Best solution by Stack Overflow
- How to use GUI in c language?Which is best GUI for c?Best solution by Quora
- What are some best practices to follow when designing for users completely unfamiliar with computers?Best solution by User Experience
- Where best can one learn c,c++ from?
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.