Is there a design-pattern which is recognized as the best pattern to use when separating a datamodel and a gui drawing mechanism?
So say i have a class Circle and a class Square, then i would be tempted to have a draw method in both these classes. However that would force the class to import all kinds of nasty things depending on the drawing canvas im using (swing,j3d,opengl,etc).
My first thought would be that a Visitor pattern could solve this by making Square and Circle implement a method which takes a visitor as an input argument and calls a function on the visitor. then i could have two draw methods on the visitor which takes a Circle and a Square instance as input argument, and draws them accordingly.
Any suggestions on this?
There is no “best” method, it all depends on you platform, architecture and other stuff.
Usually, when it comes to GUI, several patterns should be combined.
One of them is usually the MVC where the view can be extended with other hierarchy pattern (Visitor is also an option).