Results 1 to 4 of 4
- 08-21-2012, 06:35 PM #1
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
MVC help (Model - View - Controller)
I have been reading and reading AND reading about MVC. I am seeing a bunch of arguing which is weird. I also see examples that are really really advanced. I saw a real simple calculator but it doesn't help me at least yet.
Lets say I am making a quiz app.
It has these features.
-You can select the keys you want to be tested in.
-You can select the time before it shows the answer or turn of timing.
-It is a GUI that displays the questions and answers.
Example question....
What is the 3 and 7 of Am7?
Example answer
3: C
7: G
Simple as that. (until I add more types of quizes and options.
Now these are calculated and strings are put together with an algorithm because there are tons of possibilities.
Currently my idea is to use a well put together Enum that I can get data from to use with algorithms.
So what types of methods would the M, V, and C have?
This is where I am having trouble with. I know the model is the data, the controller communicates between model and view. The view talks to the controller and displays GUI. But this does not help me understand how to actually do this.
UML examples with methods and variables would help a lot I think.
- 08-21-2012, 07:23 PM #2
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
Re: MVC help (Model - View - Controller)
I'm not really sure what you are asking about. I think the MVC pattern is very clear and easy to get into, though I've taken a course that focuses purely on OOP and with MVC as it's core design pattern.
The model contains all the data and logic that the program needs to be able to run. This is all the code for checking your answers, picking questions, and so on.
The controller takes instructions from the view (system operations), and calls the correct corresponding methods in the model.
The view contains NO logic at all (or shouldn't at least), only code that is associated with the GUI.
The model should never communicate directly with the view, this is the task of the controller. If you have a big program, you can implement several controllers that do different tasks.
Please be more specific in your questions and I might be able to answer better!
(Note, I'm still a newbie and I'm not saying that I'm one hundred percent correct, so if anyone knows better feel free to correct me!)
- 08-21-2012, 09:07 PM #3
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Re: MVC help (Model - View - Controller)
Obviously its not very clear and easy to get into for me.
Ok lets start here... which is the best to create first.
- 08-21-2012, 09:30 PM #4
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
Re: MVC help (Model - View - Controller)
Sorry if my post offended you in any way. Just remember those small "rules" about what each layer should do and in what way they (should) communicate.
How familiar are you with UML and a program to create UML diagrams? It's a good idea to look into programs that can do this for you. I myself use astah, which can be found here: Change Vision
There are several guides to astah and how to get started with it.
First of all, write a specification to your program. This can look something like this:
1. User starts program.
2. User clicks the "Select category" button.
3. A pop-up window appears with categories.
4. User selects a category and clicks ok.
5. The program presents a question.
6. The user inputs the answer.
7. The program checks if it's correct or not.
From this, you can create a class diagram. A good idea here is to pick all the potential classes or attributes in your program specification and make them into classes. Some of these are perhaps better as attributes in other classes, where you can place them after some thought. There wouldn't be that many classes from that specification I wrote above, but I think you get the idea of it.
When you've written down all of your classes to use, you can go on and create a sequence diagram. In this diagram you translate the specification and the system operations to more "code"-like structures and illustrate it in a diagram.
Look at the following sequence diagram:

As you can see, you are already here creating the skeleton of your code since you are figuring out the method names of your methods. You also see what methods you have to create.
You can also create a communication diagram:

When you have all this, it's quite easy to start coding. You know what you need to code, and it doesn't really matter where you start coding. Your GUI is just a GUI, and the action listeners on your buttons are calling system operations in the controller, that in turn calls methods in the model package.
I understand that this is probably just a lot of gibberish, but I can't really explain it better without having to write a lot about each segment. I learned this by reading in this book:
Larman: Applying UML and Patterns, third edition (Prentice-Hall 2004) ISBN:0-13-148906-2
and I can strongly recommend it. It goes through the ideas of creating UML diagrams and common design patterns.
Good luck!
Similar Threads
-
Model View Controller Help
By gavo87 in forum NetworkingReplies: 0Last Post: 01-12-2011, 05:29 PM -
mvc-model view controller
By hannes in forum AWT / SwingReplies: 5Last Post: 01-08-2010, 05:52 AM -
Model View Controller with Java
By chopram in forum New To JavaReplies: 8Last Post: 06-07-2008, 09:18 PM -
Model-View-Controller
By Abnoba12 in forum Advanced JavaReplies: 1Last Post: 05-15-2008, 12:32 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks