views:

44

answers:

2

I am trying to determine that if (before I start) on a new project I can pick some suitable patterns which will help with development as the project gets more complicated.

The Scenario

To have an application that draws 'simple' lines on the screen. Ideally encompassed into a 'Render Engine' which I can package into Silverlight, WPF demo applications etc.

I also require editor application that uses the render engine to do the bulk of the displaying, however provides additional functionality like control points for moving the lines about the screen & Dialogs for changing the colours of the lines etc.

The Goal

To keep the render engine specalised and efficient. The editor should be able to 'inject' the additional functionality (i.e. display of control points) into the objects used by the rendering engine, or into the render engine itself. I don't want to code any editor specific code into the render engine.

My thoughts so far

I'm thinking of using an encapsulation/template pattern for the objects that will be used by the rendering engine, somehow allowing the editor application to supply a class to the object which 'tacks on' the functionality for the control points (and for example the event handling for moving of the control points).

My reason behind liking this idea is that the rendering engine never need know about the environment in which it is working. The editor can be changed extensively without ever having to change the rendering engine (hopefully).

But....

I may be wrong, if anyone can see any pitfalls, or has experience of better ways to tackling this problem I would love to hear them!

+1  A: 

Well shoot, that's an impressive amount of forethought.

My philosophy has always been, use a design pattern when you need to use one. Otherwise you may become an architecture astronaut, designing grand schemes all for naught. It's good that you're thinking about design before development, but really, how much can you possibly know about the project before any code has been written? Just about nothing. And if you force yourself into a pattern before any code has been written, you may end up jamming a square peg into a round hole for the entire lifecycle of the application.

My advice to you: write a prototype first. Quick and dirty. No real design; just make a skeleton that walks. Learn from it. If you thought of a better way, scrap the original and redesign a new one. Use design patterns that make sense as you add functionality, not for the sake of adding functionality.

Charlie
Ahh you see there are various aspects that I know patterns will be useful for, for example undo functionality with the editor, adding 'special effects' with decorator patterns etc. In a way I just waiting for someone to say 'don't use a singleton'...
Ash
Oh I'm not denying the usefulness of patterns. They are extremely useful. But at this stage in the game, you have no code or real understanding of how you are going to solve the problem. So how can you possibly know what patterns are going to work the best? You can always refactor existing code to use a new pattern. But if you're writing all new code and demanding that it fit a pattern- well that could be tough after a while.
Charlie
+1  A: 

I agree with Charlie that you should start with a simple design prototype and extend it as needed (that's how I started with my map rendering engine). I can give you a few suggestions though:

  • Separate the drawing engine from the rest of the code (here's an example how). By the drawing engine I mean the code that actually draws something on the screen/bitmap. It should consume drawing primitives, not some higher-level entities. This way you'll be able to switch the drawing engine easily (example: SVG, PDF, GDI, WPF...)
  • If you want to have an editor, one of the patterns that are useful is the State pattern
Igor Brejc
Excellent - just the kind of information I am looking for!
Ash