Suppose you need to design a drawing program that relies on a geometric kernel library.
Inside the geometric kernel library, you have the definition of Line
, Circle
, Ellipse
classes with all the geometrical data (position, radius) and functions (area, perimeter, tangentAt).
The actual program should extend these geometric kernel classes to add drawing functions but you don't want to have DrawableLine
or DrawableCircle
classes on the UI side: entities classes must be unique.
The final goal is to have a single collection of entities in the geometric kernel, that can also be used in the drawing application to do the actual drawing.
I am using C# so I cannot use polymorphism.
- The first idea I had is to add a null field to the geometric entity base class (something like
object Renderer
) that would be populated and used in the drawing application to do the actual drawing (at the cost to cast to proper types it all the times).
What other options do I have?