Reputation: 1
I do have an application which deals with drawing on a WPF Canvas some lines and shapes and adding many points say 1000 on the drawn line .
which design pattern suits this highly extensive canvas drawing in wpf..
Is MVVM a better apporoach for this line drawing and point plotting stuff ?
Any help/ideas are highly appreciated.
Regards, Sreekesh NK
Upvotes: 0
Views: 773
Reputation: 10357
Here is a basic overview of the design that you could consider using:
(Im a C++ guy, but I think you'll get the idea)
class ScreenBase
{
public:
// define abstract operations here, may consider different return types
// These may be Template Patterns depending
// if there is common stuff to all screens
virtual void drawLine(/* appropriate params here*/) = 0;
virtual void dragLine(/* appropriate params here*/) = 0;
virtual void deleteLine(/* appropriate params here*/) = 0;
// more common operations
// Use a Template pattern if there is common screen
// serialization stuff, else just define it as abstract
void serialize() {
// do common stuff here
doSynchronize();
// do more common stuff here
}
virtual void doSynchronize(/* appropriate params here*/) = 0;
...
private:
// store the drawing shapes here appropriately
};
class Screen1 : public ScreenBase
{
public:
// concrete operation implementations
virtual void drawLine(/* appropriate params here*/);
virtual void dragLine(/* appropriate params here*/);
virtual void deleteLine(/* appropriate params here*/);
virtual void doSerialize() { ... }
// concrete specifics here
};
// class Screen2 : public ScreenBase
// class Screen3 : public ScreenBase
// I dont know the Microsoft stuff, the shapes should be
// defined in WPF, So we wont need to define anything here.
Instead of the Screens implementing the serialization, you may consider using a Stategy Design pattern, which would be to create a seperate serialization class or class hierarchy and set that as an attribute on the Screen(s)
Try this out, then as you advance more, try to ask more specific questions
Upvotes: 0
Reputation: 2064
Shapes and line drawing is UI specific so in MVVM this would live in the View.
If you were to persist the lines and shapes, then maybe the Model and ViewModel would get involved, but to be honest design patterns don't seem to come into what you are asking.
MVVM, MVP, MVC - all these patterns are enterprise architecture patterns. They are concerned with a composite breakdown of your solutions layers and components, keeping them seperated so they can be tested and maintained..
Canvas drawing don't really come under particular design patterns. Sure you can use MVVM, but I can't see that affecting your specific implementation of the drawing components.
Upvotes: 1