Re: Design help needed (model view controller)
- From: "Daniel T." <postmaster@xxxxxxxxxxx>
- Date: Mon, 22 May 2006 17:23:22 GMT
In article <1148313993.960676.214460@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"BrianS" <Finster_Baby101@xxxxxxxxxxx> wrote:
I am trying to create a paint-like program in C++ for a class I am
taking. This is my first "big?" project for me. I started but my
design is too simplistic and it is becoming a nightmare. So I would
like to find a better approach and start over with a good design.
After doing some research I found the Model View Controller pattern and
I think this could be what I am looking for. I also found a variation
of this pattern called "Taskmaster" from the folks at objectmentor.com
http://www.objectmentor.com/resources/articles/taskmast.pdf
In taskmaster they create a simple "Line" class which is just basically
a definition of a line. They also have an abstract "GraphicObject"
with a draw method and then make a "GraphicLIne" that contains a Line
and can draw one on the screen. I like this design, but for my app I
am getting confused.
In my application I will also have to keep track of the pen width and
color. So I figure that I can add appropriate methods to GraphicObject
to take care of the pen and color. No problem so far.
However, I plan to keep a list or vector of objects that the user wants
drawn in the model, but that fact that it now has drawing information
like pen width and color and is in the model troubles me. Isn't that
breaking some of the decoupling rules? Pen width and color to me seem
to belong to the view, no? If I try to maintain a list of simple
objects (without pen width and color) in the model and another list in
the view (with width and color) that seems bad too. Either this is
duplicating my effort or I can see these lists possibly getting out of
sync. So now what?
It can sometimes be hard to determine what should be in the model and
what should be in the view, especially for a drawing program or game.
Maybe this will help... Imagine that you need to transmit a drawing from
one computer to be displayed on another. You want to minimize the amount
of data that gets transmitted, but at the same time, you need to fully
describe the picture. Anything that can reside in the receiving program
without having to be transmitted is part of the View, anything that must
be transmitted is part of the Model.
If I were to describe to you how to draw a picture of a house with some
crayons, it wouldn't be enough for me to say, "draw a line from here to
there." I would also have to tell you which crayon to use, and probably
I would have to tell you how thick to make the line. I am the Model, and
you are the View.
I also thought that this (array or vector or list) of objects (my
model?) could be used to repaint
the screen through the view when necessary. I hope this made some
sense. So what's the best way to go about this?
IMO, the View should not duplicate any of the information in the Model.
When it comes time to repaint, the View should again consult the Model
to figure out what to repaint and how. This ideal may need to be
sacrificed on the altar of efficiency sometimes, but don't do that until
you find you have to.
.
- References:
- Design help needed (model view controller)
- From: BrianS
- Design help needed (model view controller)
- Prev by Date: Design help needed (model view controller)
- Next by Date: Re: Searching OO Associations with RDBMS Persistence Models
- Previous by thread: Design help needed (model view controller)
- Next by thread: Re: Design help needed (model view controller)
- Index(es):
Relevant Pages
|
|