maybe you’ve already considered this… make an interface representing your Graphics needs and a factory method that produces the right type based on OS. So if it’s Mac a MyMacGraphics is returned or a MyWindowsGraphics on Windows, but they’re both of the interface. One of them will simply call through, drawRect code is just drawRect. The others may have to do a bit of fudging to give the same results. Like maybe line thickness is handled differently on different OSes.
By having the factory return a corresponding OS graphics you can write a single drawing routine, no need to maintain separate chuncks of drawing code. For PDF you’ll need to pass some flag to the factory method (because its not OS based), or make another factory method just for PDF graphics. After that choice for PDF though you can draw to the graphics the same as any other. When iOS comes out you just need to make a MyIOSGraphics that will produce the same results as the others. You’ll maintain separate classes for each destination but drawing code is homogenous.
[code]Interface iMyGraphics
Sub drawRect(x, y, w, h)
End Interface
Class MyMacGraphics implements iMyGraphics
Sub drawRect(x, y, w, h)
g.drawRect(x, y, w, h) //call through
End Sub
End Class
Class MyWindowsGraphics implements iMyGraphics
Sub drawRect(x, y, w, h)
g.drawRect(x + g.PenWidth \ 2, y + g.PenHeight \ 2, w, h) //match behavior
End Sub
End Class
Class MyPDFGraphics implements iMyGraphics
//…
End Class
Module GraphicsFactory
Function NewGraphics(pic As Picture) As iMyGraphics
if TargetMacOS then
return new MyMacGraphics
elseif TargetWindowsOS then
return new MyWindowsGraphics
end
End Function
Function NewPDFGraphics(destination As MyPDFThing) As iMyGraphics
//…
End Function
End Module
//usage
dim pic As new Picture(w, h)
dim g As iMyGraphics = GraphicsFactory.NewGraphics(pic)
g.drawRect(10, 10, 10, 10)
…or maybe make the factory an extension method…
dim g As iMyGraphics = pic.MyGraphics[/code]
I didn’t illustrate how constructors might be hidden or Picture/PDF references passed in or stored. It’s basically just an interface that’s implemented to give identical results to different destination types.