Subclassing Object2D

Hello,

I’d like to add properties to the Object2D class and have them also available on its subclasses (CurveShape, RectShape, etc.), but I don’t see how to achieve this without basically re-creating them all.

If I define a new class “MyObject2D”, then, obviously, a CurveShape won’t be a subclass of it. If I also create “MyCurveShape as MyObject2D” (…), then it won’t be a curve shape at all. And if I create “MyCurveShape as CurveShape”, it also won’t be a subclass of MyObject2D.

I never dealt with Object2D before this project, thus my troubles in doing this. On the other hand, I’m sure it’s a basic OOP concept, but I never dealt with this specific case either.

Is there an “obvious” path I’ve not considered?

Use extends and some global module, which has a dictionary with weak references to the object and references for their properties.

1 Like

Thank you for your answer.
It basically looks like my first idea: have a property (as an array of Object2D objects) whose each element would share the meaning of the property.
So, in my case, I’d have this:
HiddenItems() As Object2D

But I’m concerned by speed and unnecessary “resource-intensive” code. When drawing, I draw every object (currently) with a loop. Now, I’d have to check if HiddenITems.IndexOf(ThisObject)=-1 before each drawing. And I’m guessing IndexOf is slower than accessing a property.
Now, I may not notice a huge difference with just this, but once I get to add “a lot” of “properties” in the future, I’m fearing it will become slow.

Is this a fair fear?
(nice words…)

Another option would be to have your own class that holds the Object2D as a property, and your other properties as additional properties of that class.

If you still want things to draw as Object2D’s normally would then you dont have a choice but to subclass each and add whatever properties
Otherwise you would need to insert your new superclass between Object2D (the relatively generic super class) and each of the specialized Object2D classes like CurveShape etc

The rest of the options are workarounds that will work with varying degrees of difficulty :stuck_out_tongue:

Great idea, thank you.
And shame on me, as I’ve used this technique previously, years ago, for an AppleEventRecord bug’s workaround, and didn’t see it this time… I guess my learning curve toward shapes (new to me) don’t make me thinking right… :thinking:

1 Like

Yes, I’m not afraid, as I’m not a newbie either and have done several “complex” things already :wink:. But, as a non-professional programmer, I don’t always plan or think deep enough.
Anyway, Object2D is a new area for me. I wanted to experiment them to see whether they’d suit my needs. For now, it’s ok, but in the long run, I’ll be unable to do advanced things (like pattern drawing, etc.).
Not sure yet whether I’ll avoid extra functions or convert the object2d to custom classes later.
I’m wondering whether Object2D classes are complete enough or just poor classes for basic drawings only (their philosophical reason in the framework; are they meant to be enhanced in the future?).