Results 1 to 4 of 4
Like Tree2Likes
  • 2 Post By Zyril

Thread: MVC help (Model - View - Controller)

  1. #1
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default 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.

  2. #2
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default 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!)

  3. #3
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default 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.

  4. #4
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default 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:

    MVC help (Model - View - Controller)-sequencediagramenrollinseminar.jpg

    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:

    MVC help (Model - View - Controller)-communicationdiagram.jpg

    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!
    Fubarable and HalfAZN like this.

Similar Threads

  1. Model View Controller Help
    By gavo87 in forum Networking
    Replies: 0
    Last Post: 01-12-2011, 06:29 PM
  2. mvc-model view controller
    By hannes in forum AWT / Swing
    Replies: 5
    Last Post: 01-08-2010, 06:52 AM
  3. Model View Controller with Java
    By chopram in forum New To Java
    Replies: 8
    Last Post: 06-07-2008, 10:18 PM
  4. Model-View-Controller
    By Abnoba12 in forum Advanced Java
    Replies: 1
    Last Post: 05-15-2008, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •