views:

45

answers:

3

Hello all,

I having trouble figuring out the correct architecture for this kind of application: it's a diagramming application, which resembles MS Visio. The diagrams are used to generated data which is passed to another application.

When designing applications, I've always tried to used layering, but now I can't decide how to do this when the data is so tightly coupled with the presentation. For example, a certain object in my canvas has a (X,Y) data, which is used for presentation purposes only, but has to be stored like domain data.

Where I'm getting things wrong? I'm pretty sure I'm looking at this from the wrong angle, but I can't figure out the right one.

Thanks again!

UPDATE:

I'm also aware that maybe I shouldn't be separating UI from domain in this case. If that is so, please provide me with some rational of when to apply separation and when not to.

A: 

You could try to implement some kind of view model, which saves the current layout of your objects. This way, x/y values together with the id of the object are stored in a layout file while pure model data is stores elsewhere.

Maybe this helps a bit,

Juri Keller
+1  A: 

I think you need to make sure you're keeping the what and the how separate. What you are displaying is abstract, sets of coordinates, shape types. How you're displaying it is very specific. I'd make sure the domain model dealt purely with the what and the view layer dealt uniquely with the how. It's hard to get into specifics though without knowing more about your app.

Joeri Sebrechts
+1  A: 

In a diagramming tool the x/y position of a shape is part of the domain data (the location of the shapes is part of the diagram - you cant draw the diagram without it), the code that use those x/y coordinates and draw a shape on the screen is part of the presentation tier.

I know some people think that data that is only used for display should be saved separately, but in every project I've ever worked on that saved data separately this turned up to be a huge maintenance and support nightmare.

In a simple diagramming tool (if the tool just draws and edit the diagram without any fancy processing based on the diagram) there is no business logic, there's only the code that draws and edit the diagram (that belongs in the presentation tier) and the diagram data (that is the domain model).

If there is no business logic, by using a separate set of objects for domain and presentation you'll have to duplicate all your model data twice (once in the model objects and once in the presentation objects) and you won't get any advantages from separating the business logic from the presentation (because there isn't any).

On the other hand, if you do have some algorithms you run on the data you do have something to gain by separating the graph data from the drawing code - you can run the algorithm outside the tool, you can have better automated tests, etc.

also if you write another system that operates on the same data you can at least share the model definition and save/load code if you separate it from the drawing code.

So, let's summarize:

  • All the diagram data is part of the model (including data only used for presentation purposes).

  • Anything that draws to the screen or handles user input is in the presentation tier (obviously).

  • If those two cover all your code and data than your application don't have any "business logic" and the tier separation is probably overkill.

  • If you have any code that doesn't fit into those two categories and you think it should be part of the model than you should build the two separate tiers.

  • If there's any chance for code sharing between systems you should make sure the shared code is not mixed in with the presentation code.

  • And one last "bonus" point - if this is a project that's likely to be in active development for a long time with new features added in the future - you may want to separate the UI/data anyway just to make future work easier - you have to decide if this future saving is worth the extra time now and if this separation is really likely to help in the future.

Nir
I was afraid that the bounty would end without any the answer I wanted. The other answer was good and I upped it, but it didn't untied the knot in my mind. Your's has, with the idea: code that draws the shape is presentation, the shape itself is domain. Besides, with the level of detail presented, the answer is well worth the bounty. Thanks a lot for the help.
Bruno Brant