OOP: subclass method overriding vs re-using

Hello,

I understand I can override a method/event in a subclass, but how can I re-use the super/base/parent class method and add some code to it?

In other words, in the subclass I want to do the same as in the super/base/parent class plus some additional code.

Thanks,
Stan

Create an Event Definition with the same definition as the Event Handler you’re overriding.
Do all your overriding, and then at the end of the Event Handler call the Event Definition.

[quote=323326:@Stan F]Hello,

I understand I can override a method/event in a subclass, but how can I re-use the super/base/parent class method and add some code to it?

In other words, in the subclass I want to do the same as in the super/base/parent class plus some additional code.

Thanks,
Stan[/quote]
http://developer.xojo.com/super

Now I see something I don’t understand:
WebTextField1 is a subclass of WebTextField
WebTextField2 is a subclass of WebTextField1.

After I defined event Shown on WebTextField1, that event has disappeared from WebTextField2. See the screenshot
WHY?


screenshot

Thanks,
Stan

At http://developer.xojo.com/home there are tons os webinars, tutorials and even a free book we commissioned
And the answers to this latest question, along with several other questions you’ve posted, is all covered in the user guide
And if you dont want to read them online there are PDF’s copies in the “Documentation” directory located right next to the Xojo IDE executable and accessible through the Help menu in the IDE itself
Do go through them as they will answer a TON of questions a lot faster than asking them all here one at a time
And they can be consulted even when most of us are sleeping and unavailable to answer questions

Specifically see the Events entry on http://developer.xojo.com/userguide/properties-methods-and-events

Events in Xojo implement something akin to “Chain of Responsibility”
While methods in subclasses can call methods in the super class, events go the other way from top of the class hierarchy down.
In the simple case they go down through the class hierarchy until something implements the event handler and once thats done nothing further down the hierarchy even knows the events exists
Hence you see the case you described where once the superclass, WebTextField1, implemented the event its unavailable to anything further down the hierarchy

And thats perfectly normal

You actually have to do some work to make it so that even if the superclass implements the event it it also passes it along (if need be which is NOT always the case)

And this is where and why, I’m suggesting reading the docs, seeing if they clarify things for you and IF they do not, come back and ask again.

First you may find you ask better questions, or at least ones that are not already covered in the documentation.
Most members of the forums appreciate it if you can say “Hey I read the docs on X and I checked the webinars and I still dont understand …” or something saying you’ve done everything you can to find the answer.

You will get more replies and probably better answers than “Read the documentation”

I watched a few videos on YouTube, reviewed examples, and I am in the middle of reading the textbook.
From the OOP point of view, all those resources cover areas where OOP works.
(Of course, they don’t cover areas that don’t work.)

I am new to Xojo and I am sorry if my questions seem to be annoying. On the subject of OOP in UI, I couldn’t find anything discussing it and I simply didn’t know if I had missed something or it wasn’t implemented.

Thanks,
Stan

As a beginner, I feel you will rarely need to subclass a control. The need arises when you want to add something to all instances of that control. A good example is the Listbox. It’s perfectly fine until you want to have an alternating row color. Then, you have two options:

The first is to implement that CellBackgroundPaint event in every Listbox you’ve used in your project. If it’s just one or two that’s not a big deal, but if you have 50 then that’s a pain.

So you subclass the listbox and implementing that code in the subclass makes sense. Then you change the super of all your list boxes to your new subclass and voila, you’re done. If you want to change how it works you only have to do it in one place.

If you are a visual person and like seeing how someone with 15+ years of experiences using Xojo, I’d highly recommend my video training at http://xojo.bkeeney.com/XojoTraining/. 65+ hours of video for subscribers including 2 start to finish desktop apps, and 1 start to finish web app. That’s over 200 videos. Last time I looked I had streamed over 10,500 hours of video to developers all over the world.

Norman,

[And this is where and why, I’m suggesting reading the docs, seeing if they clarify things for you and IF they do not, come back and ask again.]

OK, maybe I didn’t read and watch everything available, :slight_smile: but I did some homework.
However, if you are so confident about documentation, please tell me where I can find a document or video about how XOJO object-oriented features can be used to build a website. (I don’t mean a trivial class example, but a full website project with many levels of subclasses and subclasses used for UI {I don’t need classes to store data. My data is stored on SQL Server}. All examples of classes in the official Xojo documentations and videos were trivial).

Bob, I will definitely subscribe and watch your videos. Thanks!!!

BTW, I am new to Xojo, but I have lots of experience in other OOP language. I am wondering how much of my previous experience I can use in Xojo. In general, web programming is extremely competitive with lots of free tools. Still, Xojo has some positive aspects.

Thank you,
Stan

[quote=323346:@Stan F]Norman,

[And this is where and why, I’m suggesting reading the docs, seeing if they clarify things for you and IF they do not, come back and ask again.]

OK, maybe I didn’t read and watch everything available, :slight_smile: but I did some homework.
However, if you are so confident about documentation, please tell me where I can find a document or video about how XOJO object-oriented features can be used to build a website. (I don’t mean a trivial class example, but a full website project with many levels of subclasses and subclasses used for UI {I don’t need classes to store data. My data is stored on SQL Server}. All examples of classes in the official Xojo documentations and videos were trivial).
[/quote]
Dont mistake “the things you’re asking are covered in the docs” for “here’s a tutorial on how to implement an tire website”
That you wont find - I’m pretty sure
The docs cover the questions that you’ve asked on this & other threads

There are some sample applications in the examples next to the IDE which you can peruse but none are a “website” - an Xojo is not really a “web site builder”

I dont recall you saying what languages you’ve used before
Knowing that might make it easier to say “oh that thing in X is this in Xojo” or “you’d do this in X and this in Xojo”

In many ways Xojo has a lot of similarity with Java - single inheritance, mix ins via interfaces etc