Hi all,
I hope nobody minds me posting this question to this group, but I
couldn't find any group closer to the Subject.
Can anyone clear up where you draw the lines when dividing up an
application into Model, View and Controller parts?
For example: I have some classes:
class FlatWorld;
class Shape;
class BlobbyShape; // inherits from Shape
class StringyShape; // inherits from Shape
class GassyShape; // inherits from Shape
And my application is split thus:
Model:
The Shapes. And Flatworld which contains a vector<Shape>
View:
Class which gets information from Flatworld, and renders the Shapes.
Controller:
Class which interprets mouse clicks/drags and tells the Shapes to
move or change shape.
The other important thing I have learned is to do things Once And Only
Once (OAOO). The problem is that the MVC concept seems to break the
OAOO principle, because two classes (perhaps written by two different
people) need to know enough about the Shapes to be able to render them.
For example the GassyShape is rendered in a totally different way to
the StringyShape. Also, there are totally different methods for
manipulating the Shapes.
What happens when someone writes a new kind of Shape? The author of
the View has to be contacted and taught how to read the information and
render the shape, and he must edit his code. Ditto the Controller.
Wouldn't it be better to integrate the Controller and View into the
Model?
For example:
class Shape
{
virtual void Render(Surface *S);
virtual void Click(Point P);
virtual void Drag(Point P);
virtual void Release(Point P);
};
Now, new Shapes can be written at any time, and they take care of
themselves, simply being told when/where to render, and any mouse
actions that come their way.
I have Googled for this a lot, and read the C2 Wiki, but I still can't
find a decent resolution to this. Can anyone offer any advice?
Many thanks in advance.
Hugo Elias 7 2520 hu********@virg in.net wrote: Hi all, I hope nobody minds me posting this question to this group, but I couldn't find any group closer to the Subject.
Can anyone clear up where you draw the lines when dividing up an application into Model, View and Controller parts? [...]
I actually consider news:comp.objec t to be closer in topic to this
instead of any language newsgroup. But that's just MO. hu********@virg in.net wrote: Hi all, I hope nobody minds me posting this question to this group, but I couldn't find any group closer to the Subject.
comp.object would be my guess. It's more a gerneal problem of object
oriented programming rather than specific to C++.
The other important thing I have learned is to do things Once And Only Once (OAOO). The problem is that the MVC concept seems to break the OAOO principle, because two classes (perhaps written by two different people) need to know enough about the Shapes to be able to render them. For example the GassyShape is rendered in a totally different way to the StringyShape. Also, there are totally different methods for manipulating the Shapes.
What happens when someone writes a new kind of Shape? The author of the View has to be contacted and taught how to read the information and render the shape, and he must edit his code. Ditto the Controller.
Wouldn't it be better to integrate the Controller and View into the Model?
I think you missed the whole point of the MVC concept. The idea is that you
can vary the view and the controller independant of the model and even have
multiple views at the same time fore one model. So you can have one view
that shows you a graphical representation and another one that shows you a
textual list of the object names and properties. Or just simply two
graphical views of the same type, but each showing a different part of the
model.
Victor Bazarov wrote: hu********@virg in.net wrote: Hi all, I hope nobody minds me posting this question to this group, but I couldn't find any group closer to the Subject.
Can anyone clear up where you draw the lines when dividing up an application into Model, View and Controller parts? [...]
I actually consider news:comp.objec t to be closer in topic to this instead of any language newsgroup. But that's just MO.
Well there's a surprise, Dull Vic moans again...
Yes, I do realise that that's one of the benefits of MVC, so, for
example, I could print the shapes to paper, rather than rendering them
to the screen.
But even in this case, I think the same question applies. Surely, if
the application is divided this way, then changes to the model have to
affect the view and the controller also?
Integrating the rendering code into the model still lets me have
multiple views of the model at the same time. For example I could just
tell my models to render themselves to different places:
Shape.Render(dc 1, RenderSettings1 );
Shape.Render(dc 2, RenderSettings2 );
It seems to me that MVC depends how much is likely to change. If the
model (code) changes often, and new Shapes appear and require different
access functions, requiring constant updates to the view (code), then
it hardly seems worth having separate M,V,C.
But if you can have a totally consistent set of member functions for
all the Shapes, then no changes are ever needed to the view, and the
MVC concept does help.
I can see both sides of the argument. Two sensible ways of dividing
the application are pulling in different directions. Is there anyone
who has encountered a problem like this, and can shed any light?
Many thanks again, and sorry for the slightly OT posting. I'll aim
for comp.object next time.
Hugo Elias
<hu********@vir gin.net> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com... Yes, I do realise that that's one of the benefits of MVC, so, for example, I could print the shapes to paper, rather than rendering them to the screen.
But even in this case, I think the same question applies. Surely, if the application is divided this way, then changes to the model have to affect the view and the controller also?
Integrating the rendering code into the model still lets me have multiple views of the model at the same time. For example I could just tell my models to render themselves to different places:
Shape.Render(dc 1, RenderSettings1 ); Shape.Render(dc 2, RenderSettings2 );
It seems to me that MVC depends how much is likely to change. If the model (code) changes often, and new Shapes appear and require different access functions, requiring constant updates to the view (code), then it hardly seems worth having separate M,V,C.
But if you can have a totally consistent set of member functions for all the Shapes, then no changes are ever needed to the view, and the MVC concept does help.
I can see both sides of the argument. Two sensible ways of dividing the application are pulling in different directions. Is there anyone who has encountered a problem like this, and can shed any light?
Many thanks again, and sorry for the slightly OT posting. I'll aim for comp.object next time.
Hugo Elias
I find that hard-and-fast rules tend to be so inflexible as to render them
useless in many practical applications.
I do a lot of work in both the Mac and Windows environment, and the handling
of mouse events and keyboard entry and files are different between the two.
But in both platforms, my mouse events and my drawing itself need to be
handled by a class that's appropriate to the platform.
For example, on Windows, I've got a window class that's handling all mouse
events, and it passes on ones that are of interest to what I guess you'd
call a controller class. That controller class uses a pointer to the window
that called it (and the "device context" for that window) in order to place
the graphical objects where I want them. I pass that "graphical context"
information down to the individual graphical objects (shapes), and let them
draw themselves. (I pass this info in a small class of my own design whose
sole purpose is to hide the details of that graphical context information,
making my interfaces consistent across platforms.)
My "controller " class certainly knows about each of the types of objects
that it might contain, although that's really only needed because it has to
create them (and store them as a pointer to the base class type). My
"view", or window class, doesn't know about the shapes at all; it only knows
about the controller class. And my shapes simply use virtual functions to
draw, copy, hide, move or whatever, using the "graphical context"
information. (This same type of information is passed to different
functions for streaming internal info, or for rendering to a "printer"
context.
Using this type of design, I can write a different view class to support
each platform and different (but similar) shape classes to support each
platform, and the controller really only needs minor adjustments to handle
passing different types of handles or pointers to the view, based on what
the platform requires (e.g., an HDC, HANDLE, WIndowPtr, etc.).
-Howard
Howard a écrit : <hu********@vir gin.net> wrote in message news:11******** *************@z 14g2000cwz.goog legroups.com...
Yes, I do realise that that's one of the benefits of MVC, so, for example, I could print the shapes to paper, rather than rendering them to the screen.
But even in this case, I think the same question applies. Surely, if the application is divided this way, then changes to the model have to affect the view and the controller also?
Integrating the rendering code into the model still lets me have multiple views of the model at the same time. For example I could just tell my models to render themselves to different places:
Shape.Render( dc1, RenderSettings1 ); Shape.Render( dc2, RenderSettings2 );
It seems to me that MVC depends how much is likely to change. If the model (code) changes often, and new Shapes appear and require different access functions, requiring constant updates to the view (code), then it hardly seems worth having separate M,V,C.
But if you can have a totally consistent set of member functions for all the Shapes, then no changes are ever needed to the view, and the MVC concept does help.
I can see both sides of the argument. Two sensible ways of dividing the application are pulling in different directions. Is there anyone who has encountered a problem like this, and can shed any light?
Many thanks again, and sorry for the slightly OT posting. I'll aim for comp.object next time.
Hugo Elias
I find that hard-and-fast rules tend to be so inflexible as to render them useless in many practical applications.
I do a lot of work in both the Mac and Windows environment, and the handling of mouse events and keyboard entry and files are different between the two. But in both platforms, my mouse events and my drawing itself need to be handled by a class that's appropriate to the platform.
For example, on Windows, I've got a window class that's handling all mouse events, and it passes on ones that are of interest to what I guess you'd call a controller class. That controller class uses a pointer to the window that called it (and the "device context" for that window) in order to place the graphical objects where I want them. I pass that "graphical context" information down to the individual graphical objects (shapes), and let them draw themselves. (I pass this info in a small class of my own design whose sole purpose is to hide the details of that graphical context information, making my interfaces consistent across platforms.)
My "controller " class certainly knows about each of the types of objects that it might contain, although that's really only needed because it has to create them (and store them as a pointer to the base class type). My "view", or window class, doesn't know about the shapes at all; it only knows about the controller class. And my shapes simply use virtual functions to draw, copy, hide, move or whatever, using the "graphical context" information. (This same type of information is passed to different functions for streaming internal info, or for rendering to a "printer" context.
Using this type of design, I can write a different view class to support each platform and different (but similar) shape classes to support each platform, and the controller really only needs minor adjustments to handle passing different types of handles or pointers to the view, based on what the platform requires (e.g., an HDC, HANDLE, WIndowPtr, etc.).
-Howard www.wxwindows.org hu********@virg in.net wrote: Hi all, I hope nobody minds me posting this question to this group, but I couldn't find any group closer to the Subject.
Can anyone clear up where you draw the lines when dividing up an application into Model, View and Controller parts?
For example: I have some classes:
class FlatWorld; class Shape; class BlobbyShape; // inherits from Shape class StringyShape; // inherits from Shape class GassyShape; // inherits from Shape
And my application is split thus:
Model: The Shapes. And Flatworld which contains a vector<Shape>
View: Class which gets information from Flatworld, and renders the Shapes.
Controller: Class which interprets mouse clicks/drags and tells the Shapes to move or change shape.
The other important thing I have learned is to do things Once And Only Once (OAOO). The problem is that the MVC concept seems to break the OAOO principle, because two classes (perhaps written by two different people) need to know enough about the Shapes to be able to render them. For example the GassyShape is rendered in a totally different way to the StringyShape. Also, there are totally different methods for manipulating the Shapes.
What happens when someone writes a new kind of Shape? The author of the View has to be contacted and taught how to read the information and render the shape, and he must edit his code. Ditto the Controller.
Wouldn't it be better to integrate the Controller and View into the Model?
For example: class Shape { virtual void Render(Surface *S); virtual void Click(Point P); virtual void Drag(Point P); virtual void Release(Point P); };
Now, new Shapes can be written at any time, and they take care of themselves, simply being told when/where to render, and any mouse actions that come their way.
I have Googled for this a lot, and read the C2 Wiki, but I still can't find a decent resolution to this. Can anyone offer any advice? Many thanks in advance.
Hugo Elias
I think you cannot find a decent solution, because you want to do a two
way dispatching inheritance scheme. This is not impossible to do in C++,
but you can do it numerous different ways - each with its own advantages
and disadvantages.
Maybe you would like to look at the different patterns that exist (e.g.
in Gamma's pattern book). But I think the problem you are having is far
too generic to propose a good solution...
Good Luck,
Tom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tony Marston |
last post by:
For those who you thought my method of implementing OO principles in PHP was
totally wrong - see http://www.tonymarston.co.uk/php-mysql/good-bad-oop.html
for details, you can now read
http://www.tonymarston.co.uk/php-mysql/model-view-controller.html and tell
me why my implementation of the MVC design pattern is totally wrong.
Go on, I dare you. Make my day.
--
Tony (a legend in his own lunchtime) Marston
|
by: Droolboy |
last post by:
I'm trying to build a fairly small (max. 10 different pages) site
using php, and it's becoming obvious that I need some kind of model
view separation.
Having done a few searches, I've come across the concept of 'template
engines', but that seems like overkill for my needs. I'm thinking I'll
just stick with php as my template language; a little embedded code in
the view pages, for loops or whatever, should be ok..
I've come up with the...
|
by: pysim |
last post by:
Hi, I have a couple of general requests for pointers to python
examples and design advice.
I'm looking for examples of MVC-based GUI controls done in python
(model-view-controller).
Also, examples where something like a simulation model running in its
own thread sends fast updates to a GUI in near real-time. The only
examples I've seen, such as SimPy, wait until the model is finished
running before outputting data.
|
by: Fritz Bosch |
last post by:
We are in the process of refactoring our GUI-based test application
for radio equipment and are rewriting a significant part in Python.
The new architecture will substantially be based on the
model-view-controller pattern, as follows:
User Input
|
v
+-------------+ service request service request +-------------+
|
by: Robert W. |
last post by:
I'm building my first major C# program and am try to use best practices
everywhere. So I've implemented the "Document/View Model" whereby:
- There's a Windows Form, which we'll call "formView"
- There's a Class, which we'll call "classDocument"
Thus, when an instance of each the form and the class are instantiated, they
each will hold the same data, albeit be independent of each other.
To keep the two in perfect sync with each other,...
| |
by: Stan |
last post by:
I want to make two pages interact through a controller.
1. Page A has a grid and Add button.
2. When Add button is clicked Page B pops up.
3. User enters information and clicks Save
4. Information is saved in database
5. User goes back to Page A which gets new data from database and displays
one more row.
So, the event handler for Add button on Page A might look like:
|
by: Griff |
last post by:
Two questions really, the first one "conceptual" and the other more involved
with design:
1 - There are two schools of thought where I work on the role of the
"controller" task.
The first is that the business object will provide the business rules and
that the controller will implement the rules and then pass the result set to
the view (i.e. do most of the grunt work).
|
by: Doug |
last post by:
Hi,
I learned a little about the model view presenter pattern at a
conference this last week and am experimenting with it. It's working
pretty well but I have a question.
I am trying to use it to reset info in a combo box. Below is some
sample code for my view interface and the presenter:
public interface IDevToolView
|
by: Bill44077 |
last post by:
Hi,
I am new to the MVP pattern and one of the main reasons that we are going
this route is because we are doing Scrum with 30 day sprints - so we have a
continually morphing design. We are using TDD as well to improve our ability
to refactor... you probably all know this approach.
Although the user iterface is supposedly one of the last things that you
need to do, this is a web app and we have multiple nested Repeaters on the
page....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |