Subclass

Lets say I wish to make a new subclass of TEXTFIELD and a new subclass of TEXTAREA
and I want to add the SAME computed property to both of them…

Is there a way I can place the code ONE time, and add it to both objects…

Since it has SETTER/GETTER, I cannot see a way that makes it worth the effort (as opposed to duplicating the code in each subclass, which makes the overall code larger, and makes multiple maintenance points)

and NO, I don’t wish to make a new TEXTFIELD subclass from a TEXTAREA

I have a need to do this in a number of places, and TextField/TextArea is just one example.

I suppose you could make the backing store for the computed property a class instance
Then maybe you could lift all the common code into that class
Then adding the computed property to each class has it present in each but the code for whatever manipulations is in the class

Instead of properties, would extension methods for the getter/setter be an option?

… on the TextEdit class.

What Norman describes I know of as the Composition pattern and used it several times. It’s the only (sic) way to effectively implement multiple inheritance in a single inheritance language. Basically instead of inheriting the functionality you compose it as a property and mirror it’s methods which just call through to the property. If you need the class to also be typed as it’s composed property you can add an interface, but if you don’t need that you could also forego mirroring the methods and just expose the property which would contain some reference back to your class to act on.

None of this makes any sense (sorry).

a) I was using TextArea/TextField as an example, the same function needs to be done across subclasses of controls not necessaryily as closely related

b) the Setter/Getter needs to refer to SELF, and SELF is going to be at varying levels of the hierarchy

an example might be helpful if anyone has one

[quote=152538:@Dave S]None of this makes any sense (sorry).

a) I was using TextArea/TextField as an example, the same function needs to be done across subclasses of controls not necessaryily as closely related

b) the Setter/Getter needs to refer to SELF, and SELF is going to be at varying levels of the hierarchy

an example might be helpful if anyone has one[/quote]

Would an overloaded “getMySelf” method to determine what “self” is help?

if I have to overload everything for each control type that defeats the purpose of what I am trying to do (reduce code)

I will just duplicate the computed property in each subclass

In one of my projects I use the CurrentMethodName() method inside the getter and setter to figure out the property name and then update a jsonObject automatically as the properties are modified. Its been effective. Perhaps you could do something similar and then use introspection to get its type and update things properly. (I might be completely off here, but I figured it couldn’t hurt too much)

thanks for the help… but either my question is being misunderstood, or I am grossly misunderstanding the responses.

computed property XYZ
     SET
         SELF.abc=something
     GET
        return SELF.abc
end property

simple psuedo code of a computed property (my real code is more complex in some cases)
and abc may a new subclass property, or manipluation of an existing property

I want to reuse that over dozens of subclass of various controls… but it seems the most effective way is to DUPLICATE this in every subclass. While the CODE is the same, the meaning of SELF is different based on SUPER

In a Module:

[code]Sub XYZ(Extends rc As RectControl, Assigns value As Integer)

End

Function XYZ(Extends rc As RectControl) As Integer

Return …
End[/code]

now THAT might work :slight_smile: Thanks

but only for properties of RectControl… but not for any new properties added to the subclass

Your comment doesn’t make sense to me: you said, you wanted to avoid subclassing controls - now you are speaking of subclasses of controls… ???

Why would I create a forum topic called “SUBCLASS” if I wasn’t talking about subclasses…

[quote]simple psuedo code of a computed property (my real code is more complex in some cases)
and abc may a new subclass property, or manipluation of an existing property[/quote]

The point being… in these new subclasses I may be adding properties beyond those of RECTCONTROL… and since these new properties are at a different level than the SUPER, they can’t be accessed via a common method.

Then you’re left with copying the code from subclass to subclass (which is a bit strange in my view, because you really could add it to their parent class, RectControl).

and please tell me how I can add properties to a SUPER when the inheritance has already occurred?

See my code above.

great for assigning and getting a value… but RECTCONTROL has no PROPERTY to store the value

IE… no storage mechanism

Two possibilities:

A dictionary in the module which contains the extension methods. Don’t forget to remove each instance when the window closes, or these controls will live forever and prevent the window becoming Nil.

Create a private property in each of the subclass and in the extension method have something like this:

Sub XYZ(Extends rc As RectControl, Assigns value As Integer) Select Case rc Case IsA MyTextField MyTextField(rc).abc = value Case IsA ... ... Else Raise New // TODO End End Sub

What do you expect the getter/setter to do? Simply access a property? Or do some additional, common processing? That additional processing can be abstracted out, but the property access cannot.