MVC ?

Hi,

I'm writing a little CAD, and I'm confused about the MVC pattern: Does it apply to graphics' applications ? I mean, shouldn't each object be responsible for its own behavior, like drawing it self on the screen ?

I understand the MVC if the model is just data that can be displayed in different ways, but the shapes of a CAD should be displayed according to their specifications.

Thanls a lot for any insight on this topic.

[455 byte] By [sbayeta] at [2007-9-30 19:40:45]
# 1

That's one way to look at it.

Another would be to write a Visitor object that would take the data for a CAD object and render it. Now the intelligence for rendering lives in the Visitor, not the CAD object itself.

The rational might be that a cubic spline or 3D point has an existence separate from the rendering tool.No sense having to rewrite all your CAD objects just because you're rendering them differently. Today you're using an OpenGL renderer, tomorrow it's a Web-based VRML thing. The essence of the geometric objects hasn't changed, and shouldn't require a rewrite.

%

duffymo at 2007-7-7 0:25:25 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

> That's one way to look at it.

>

> Another would be to write a Visitor object that would

> take the data for a CAD object and render it. Now the

> intelligence for rendering lives in the Visitor, not

> the CAD object itself.

>

> The rational might be that a cubic spline or 3D point

> has an existence separate from the rendering tool.

> No sense having to rewrite all your CAD objects just

> t because you're rendering them differently. Today

> you're using an OpenGL renderer, tomorrow it's a

> Web-based VRML thing. The essence of the geometric

> objects hasn't changed, and shouldn't require a

> rewrite.

>

> %

Thanks a lot for that reply.

Basically the CAD part is rather small, and I'm pretty shure there wont be much to change in the rendering part. I also know for shure that there will be new types of shapes constantly, and I'd like to use a design to deal with them. I do not mean to touch much code every time a shape is added, since maintenance will be pretty much about that.

Given this info, do you think I should use MVC or give every shape the capability to draw it self (or any other approach) ?

Thanks again for your help

sbayeta at 2007-7-7 0:25:25 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

" I'm pretty shure there wont be much to change in the rendering part"

If you're sure, and you really have your heart set on putting the rendering code inside the objects, by all means do so. You don't need my blessing.

There's no right or wrong answer, there are only choices. If you write the code, make it work, and find that over time your maintainence life is easy, then that's terrific.

If your code is a success, and someday you find that you need a new rendering scheme, you'll wish you'd taken another approach.

Maybe another way to look at it is to have each CAD object implement a Renderable interface. Now you've isolated the rendering code in a single method. You can use a Decorator to encapsulate the rendering details. Now every CAD object can still "know" how to render itself and you can still swap out a new scheme if you need to. Both our ideas are in play that way.

%

duffymo at 2007-7-7 0:25:25 > top of Java-index,Other Topics,Patterns & OO Design...