Note that there are some explanatory texts on larger screens.

plurals
  1. POIn terms of OO design, can two-d and the three-d point classes be derived from single base class?
    primarykey
    data
    text
    <p>I`m currently working out the design for simple graphic editor, who support trivial operations for two-dimensional and three-d shapes.<br> The point is, I want to render prototype of these shapes, as MsPaint does. And at the moment it is rendering I need to store somewhere pixels from the canvas which get covered by prototype, just in case when prototype changes to restore their state on the canvas. So, I want all my shapes to support this kind of buffering (Graphic Operation is the base class for all rendering operations):</p> <pre><code>public abstract class Shape: GraphicOperation { protected List&lt;SomePoint&gt; backup; public Shape(Color c): base(c) { } public Color FigureColor { get { return color; } protected set { color = value; } } public abstract void renderPrototype(Bitmap canvasToDrawOn); } </code></pre> <p><br> The main idea is that in terms of OO design it would be great to provide the support of the buffer on base class (Shape) level, I mean for TwoDShape and ThreeDShape classes this list must be initialized in different way - for TwoDShape with TwoDPoint instances, and for ThreeDShape with ThreeDPoint instances.<br> But to do this, <b>SomePoint must be base class for both</b> two-dimensional point and three-dimensional point classes. <b>Is it acceptable in terms of OO to derive both these classes from single base class?</b><br> May be there are too many words, but I just wanted the problem to be clear for everyone.<br> <b>Edit</b>: btw, is this the good idea to derive point classes from their king of shapes? I personally see no other options, but may be it would be better if I derive it directly from shape? Now it is:<br></p> <pre><code>public abstract class TwoDShape : Shape { protected List&lt;SomePoint&gt; backup; public TwoDShape(Color c) : base(c) { } } public class TwoDPoint: TwoDShape { //... } </code></pre> <p>and the same is for ThreeDPoint.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload