Control subclass or instance

Hi,

When I drag a control such as ListBox onto a window, and it gets a name called ListBox1.

Is ListBox1 a subclass of ListBox, or is it an instance of ListBox?

thanks,
j

not sure why this is showing as Draft?

I’m seeing it now

In your example, ListBox1 is an Instance of the ListBox class.

Thank you Mark,

So when I add methods to ListBox1, they are being added as a Class Extension that are scoped for only this instance?

Also, in the Inspector, why does it show ListBox as Super?

thanks,
joey

Not sure I understand exactly what you are asking. Do you mean adding ‘Event Handlers’? These are not methods, you are adding code to the existing events within the ListBox class. They will be available only to that instance. Or do you mean you are creating methods in a module using the ‘Extends’ call - those will be available to all instances of the Listbox Class.

If you add a method to a module using the ‘Extends lbx as ListBox’ parameter, that method will be available to all listboxes throughout your project. If you create a subclass, you can add methods/events/properties to your subclass which will be available to all instances of that class. But, you need to use that class when you add it to a window, not the ListBox class.

Sorry, my mistake. When I add a method, it adds to the Window containing the control, not the ListBox.

I will restate this…
So if I add a method foo to Window1, I can then call Window1.foo

Is Window1 a subclass of Window or an Instance? I can add methods to it. And in the inspector it shows Window is Super of Window1, just like for ListBox1 it shows that ListBox is Super of ListBox1.

I guess it is the inspector showing that ListBox and Window is Super, that makes me feel ListBox1 and Window1 must be SubClasses of Super. Maybe the label in the inspector should say Class rather than Super?

WIndow1 is an instance of Window which contains an instance of a listbox (in your example)
If you add a method FOO to Window (assuming you do not make it private) than yes you can call Window.FOO

However to be valid the instance of Window1 must be active for the call to work. (Note if you have IMPLICIT INSTANCE on (which is the default, then calling WINDOW1.FOO will activate the instance of WINDOW1 if it is not already active)

Thanks Dave…

How is it possible to add methods to an Instance of a class if it isn’t a subclass? Is this using the Class Extension mechanism, which is analogous to Objective-C categories?

Also, there is still the question of why they are using the label of “Super” in the inspector.

a subclass is a whole NEW class that inherits from a superclass…

EVERYTHING is ultimately a subclass of something … all the way back to the base object

So you can have

an INSTANCE of a WINDOW which can have methods you add (as well as properties and events)… and this is ONE unique occurance that exists and executes within your app.

Then you can have a SUBCLASS of a WIndow (called perhaps myWindow), that has methods/properties and events that you have added… but being a class, you can add as many INSTANCES as required and they ALL have the methods etc that you added to the class… AND THEN you can add unique ones to each INSTANCE if required.

So TECHINICALLY … XOJO built the current WINDOW “class” from an “object” class (with a whole series of inherited from subclasses along the way)

Obj-C supports this exact same OOP model… Inheritance and Polymorphism…

It is a matter of not confusing an INSTANCE of a class/object from the class/object itself

[quote=17116:@Joey Coyle]Hi,

When I drag a control such as ListBox onto a window, and it gets a name called ListBox1.

Is ListBox1 a subclass of ListBox, or is it an instance of ListBox?
[/quote]
An instance

Thanks Dave,

I fully understand Classes, Subclasses, and the instantiation of these Classes and Subclasses into “instances or objects” in a computer science sense.

My confusion only lies in what I am dealing with in xojo.

I’m being told that when I create Window1, it is not a subclass of Window, but it looks and smells like a subclass. When I create controls such as ListBox1 from ListBox, it does seem more like an instance, and not a subclass, yet the interface in the inspector seems to indicate it is a subclass because of the use of the word “Super”.

In the documentation, it does seem to indicate that the Super field in the inspector indicates that subclassing has occurred. This is from page 155 of the Fundamentals document. In the image, not displayed here, Application is listed as Super, and App is shown in the Name field. Hence App is a Subclass of Application. The inspector shows the same relationship for Window to Window1, and ListBox to ListBox1. So I think I’m coming to the conclusion that in each of these cases, I’m dealing with instances of a subclass. So my hypothesis is Window1 is a subclass of Window, and I’m interacting with the instance of this subclass.

[quote]The Application class is used to create a subclass that represents your application. When you create a new desktop project, a subclass based on the
Application class is added to your
project automatically. This is the
App class in the Navigator. The
Inspector indicates that its Super
is Application.
On this App subclass is where you specify the default window that opens when your application starts, the default menu bar that is used by the application and the application icons.[/quote]

You cant add methods to the instance on the window

Hi Norman,

Please ignore my error with ListBox, I previously acknowledged that was a mistake. I realize now I can’t add methods to the controls in that fashion.

But the rest of my questions still remain valid I feel.

thanks,
joey

From Book 2 : User Interface on page 11

[quote]Subclasses
To use subclasses of controls in your layout, drag them from the Navigator to the Layout Area.[/quote]

So I think that answers my question.
ListBox1 is a subclass of ListBox, Window1 is a subclass of Window, App is a subclass of Application, and thus the inspector is correct in it’s use of the word “Super”.

Obviously we are dealing with instances of these subclasses, so it’s the variable name used in the code that is confusing.
It seems like ListBox1 is a variable pointing to an instance of the Class ListBox1, where ListBox1 is a subclass of ListBox. I guess I can wrap my head around that… ???

No…
Listbox1 is an INSTANCE of Listbox

and in my opinion the designation under SUPER is mis-leading… because if I’m not mistaken… LISTBOX inherits from RECTCONTROL which in turn inherits from CONTROL which in turn inherits from OBJECT

You can make your own SUBCLASS of Listbox, in which case (again my opinion) the SUPER showing as LISTBOX would then be correct…

ANYTHING you drag to a WINDOW is an INSTANCE

[quote=17159:@Joey Coyle]From Book 2 : User Interface on page 11
ListBox1 is a subclass of ListBox
[/quote]
When you drag a control onto a layout you do not create a subclass - that’s an instance.
But the instance knows what its super class is - hence why it shows you “Super”

[quote=17159:@Joey Coyle]From Book 2 : User Interface on page 11
Window1 is a subclass of Window, App is a subclass of Application, and thus the inspector is correct in it’s use of the word “Super”.
[/quote]
Yes

[quote=17172:@Norman Palardy]When you drag a control onto a layout you do not create a subclass - that’s an instance.
But the instance knows what its super class is - hence why it shows you “Super”

Yes[/quote]

In that case, is the subclassing code visible to the developer?

Hi Norman,

[quote]When you drag a control onto a layout you do not create a subclass - that’s an instance.
But the instance knows what its super class is - hence why it shows you “Super”[/quote]

But then what it’s showing is wrong. Because when I drag a ListBox onto a window, the name shows ListBox1 and super shows ListBox. If the instance knows what it’s Super Class is, why is it showing the Class here? The superclass, as stated by Dave above, is RECTControl. Or are you saying, it is an instance of the class ListBox1, and ListBox is the super class?

Also, the documentation on page 11 of the book 2 of the new documentation should be changed, because it states that subclassing is happening.

I have to agree. What’s shown is a little confusing. It might be handy and work most of the time but it doesn’t give a true representation of what is going on.