Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Learning MVC [closed]

I wish to learn how to apply MVC architecture to my Java project; mainly my work in Swing. Now there is no easy explanation or example how to write proper code using MVC in mind apart from these two I found here:

  1. http://leepoint.net/notes-java/GUI/structure/40mvc.html
  2. http://www.oracle.com/technetwork/articles/javase/mvc-136693.html

It seems to me there is not a defined MVC architecture in Java. From what I looked at it's what Java offers you at the base level of Wwing and what you can apply on your own is in the first tutorial.

Apart from the two resources above, can someone provide me with a source that can ease you in to Java MVC? A video tutorial maybe?

like image 715
user1125177 Avatar asked Jan 01 '12 15:01

user1125177


People also ask

Can you use MVC in Java?

Advantages of MVC Architecture in JavaAs components have a low dependency on each other, they are easy to maintain. A model can be reused by multiple views which provides reusability of code. Adoption of MVC makes an application more expressive and easy to understand. Extending and testing of the application becomes ...

What is MVC in Java Swing?

Swing architecture is rooted in the model-view-controller ( MVC) design that dates back to SmallTalk . MVC architecture calls for a visual application to be broken up into three separate parts: A model that represents the data for the application. The view that is the visual representation of that data.

What MVC in Java contains?

-MVC is an architectural pattern consisting of three parts: Model, View, Controller. Model: Handles data logic. View: It displays the information from the model to the user. Controller: It controls the data flow into a model object and updates the view whenever data changes.


2 Answers

Here is pretty nice example http://www.leepoint.net/GUI/structure/40mvc.html I tried to find simplest possible to let you feel the idea.

Anyway I don't like the:

Seems to me there is not a defined MVC architecture in Java.

You can use MVC, MVP and whole other patterns in various different languages. Java has nothing to do with MVC, except MVC design can be coded in Java. There are, however, some frameworks that have embedded MVC architecture and forces using it. Spring MVC is the most known - try to find more about it, maybe some tutorials.

like image 95
dantuch Avatar answered Oct 03 '22 05:10

dantuch


Model - Model represents an object or JAVA POJO carrying data. It can also have logic to update controller if its data changes.

View - View represents the visualization of the data that model contains.

Controller - Controller acts on both Model and view. It controls the data flow into model object and updates the view whenever data changes. It keeps View and Model separate.

mvc simple example

like image 26
Dhrumil Shah Avatar answered Oct 03 '22 05:10

Dhrumil Shah