• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
giugio

the role of the controller in the mvc

7 posts in this topic

Hello, i'm not understand the role of the controller in the mvc , for example:
if i have only a model with all my functions that query the db ,do other logic and return to the view the data to show(that calls the model directly) and the model is a singleton why i need a controller?
I read that decouples the model from the view , but this what means?
Can you show me an example of the benefits of the controller?
thanks.

0

Share this post


Link to post
Share on other sites

I dont know the definitions of the MVC setup.

 

To me it appears like a simplification of some good ways to structure software.

 

You have some components which each do their own thing:

Model(s) (no I/O involved)

View(s) (graphical, network, whatever output you have)

 

And these are glued together by the controller:

Controller

The controller also handles applying input to the components such that everything is notified when something changes, as well as keeping them in sync (eg. updating view with data manually extracted from model, which is glue basically)

 

Which practically is just a class that has member variables which may be other classes or references to other classes.

 

I believe the reasoning behind this pattern is to allow changing the view without disturbing the model or needing to make changes to the model, since the model should be independent of the view and work with and without a view. All the code changes needed are moved from the model (where they would have to be made if you were to make model and view highly interdependent) to the controller. Now neither model or view know of each other, and the controller is the only thing you need to touch to reconfigure your view and model setup.

0

Share this post


Link to post
Share on other sites

View and controller commonly become mixed up in the real world. In a GUI for example, a tree view widget is both a view and a controller.

 

Strict MVC would have the view do nothing but display data in response to data changes and controller would provide input from the user but it is a stretch to make this strict approach apply in real world. Qt for example has models and views but no controllers - the views take care of those roles themselves.

2

Share this post


Link to post
Share on other sites

thanks.
1)Is a good thing to make the model a singleton?
So i have always one instance and i don't fall in possible errors
2)Is a good thing create in the model all the logic with functions and call these functions from the view? or is better to create many models and share some logics with the controller
3)there are some already made mvc framework for winform .net?

Thanks.

0

Share this post


Link to post
Share on other sites

View and controller commonly become mixed up in the real world. In a GUI for example, a tree view widget is both a view and a controller.

 

Strict MVC would have the view do nothing but display data in response to data changes and controller would provide input from the user but it is a stretch to make this strict approach apply in real world. Qt for example has models and views but no controllers - the views take care of those roles themselves.

 

What is your tree view widget doing that it is bleeding over to being a controller?  Any modification of data should just be the view calling the controller.  (ie someone goes and hits the delete key on a treeview node, the widget shouldn't be performing any direct operations on the data itself, but something like controller.Delete(treeviewNode.Data)

 

Basically, one should be able to do all the data operations without the view being involved in anyway, it makes unit testing and debugging easier, and you can re-use the controller logic in multiple views.  You can have a tree view, a gantt chart, etc, all using the same controller, doing all the same logic without any duplication.

Edited by ferrous
0

Share this post


Link to post
Share on other sites

 

View and controller commonly become mixed up in the real world. In a GUI for example, a tree view widget is both a view and a controller.

 

Strict MVC would have the view do nothing but display data in response to data changes and controller would provide input from the user but it is a stretch to make this strict approach apply in real world. Qt for example has models and views but no controllers - the views take care of those roles themselves.

 

What is your tree view widget doing that it is bleeding over to being a controller?  Any modification of data should just be the view calling the controller.  (ie someone goes and hits the delete key on a treeview node, the widget shouldn't be performing any direct operations on the data itself, but something like controller.Delete(treeviewNode.Data)

 

Basically, one should be able to do all the data operations without the view being involved in anyway, it makes unit testing and debugging easier, and you can re-use the controller logic in multiple views.  You can have a tree view, a gantt chart, etc, all using the same controller, doing all the same logic without any duplication.

 

and if i move the controller.Delete(treeviewNode.Data) in the model and becomes model::instance.Delete(treviewNode.Data) is not the same?

0

Share this post


Link to post
Share on other sites

 

 

View and controller commonly become mixed up in the real world. In a GUI for example, a tree view widget is both a view and a controller.

 

Strict MVC would have the view do nothing but display data in response to data changes and controller would provide input from the user but it is a stretch to make this strict approach apply in real world. Qt for example has models and views but no controllers - the views take care of those roles themselves.

 

What is your tree view widget doing that it is bleeding over to being a controller?  Any modification of data should just be the view calling the controller.  (ie someone goes and hits the delete key on a treeview node, the widget shouldn't be performing any direct operations on the data itself, but something like controller.Delete(treeviewNode.Data)

 

Basically, one should be able to do all the data operations without the view being involved in anyway, it makes unit testing and debugging easier, and you can re-use the controller logic in multiple views.  You can have a tree view, a gantt chart, etc, all using the same controller, doing all the same logic without any duplication.

 

and if i move the controller.Delete(treeviewNode.Data) in the model and becomes model::instance.Delete(treviewNode.Data) is not the same?

 

Okay, but what if you want to re-use a view with a different model?  the controller gives you that abstraction (which you may not need, depending on scope of your project)

0

Share this post


Link to post
Share on other sites

Hello, i'm not understand the role of the controller in the mvc , for example:
if i have only a model with all my functions that query the db ,do other logic and return to the view the data to show(that calls the model directly) and the model is a singleton why i need a controller?
I read that decouples the model from the view , but this what means?
Can you show me an example of the benefits of the controller?
thanks.

First of all, MVC is a design pattern, and it makes sense to apply it only in some problems. It's hard to tell if you need a controller in your example because it's not a real problem and it's also too abstract. What does your "model" represent? When you apply the MVC pattern you're not supposed to have 3 classes named Model, View and Controller, you'll have a lot of classes that represent the state of the whole system (all of them are "the model"), some classes that output the state of some parts of the model (all of those are "the view") and some more classes that handles the input and notify the objects that need to be notified (the controller).

 

"decoupling" two things means that changing the code of one of them doesn't require to do some changes in the other (they "don't know" each other). Your example is again too simplified to see how decoupling the model and the view would be a good thing, but it's a concept that applies to other patters as well and it's a good thing to have (so making changes is easier). Let's say you have a view that has a button that affects a lot of objects of your model, from different classes that are not related in any way. If you want to call a function on all those objects, your view code must know about all the implementations of your model classes, it must know how to get access to those objects (maybe some arrays in some other class) and it must have a way to tell if an objects needs to be notified about it or not. Now, if you change any of those classes, or add more, or change some rules, you must also change your view. If you have a controller with a function modifyAll that does all this work, your view will always say controllerObject.modifyAll, and it doesn't care about anything else. Of couse, now the controllers and the model are coupled together, but now you can make any number of views ignoring the actual model. If you change something on a model you must change one controller instead of multiple views.

 

thanks.
1)Is a good thing to make the model a singleton?
So i have always one instance and i don't fall in possible errors
2)Is a good thing create in the model all the logic with functions and call these functions from the view? or is better to create many models and share some logics with the controller
3)there are some already made mvc framework for winform .net?

Thanks.

1 - As I said before, you're not supposed to have one model, the Model in MVC pattern is a group of classes. You should have classes that represent the domain, and those classes would be "the model" in the pattern. If you're making a game with classes like Character, Obstacle and Vehicle, all of those would make the model, and you'll have objects instances of them. Some of those classes will make more sense as singletons, but probably not all.

2 - If you want to apply the MVC pattern it's bad to call model functions directly from the view, if you don't care about the pattern do it the way you want it.

Edited by DiegoSLTS
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0