Why is "Extends" limited to module methods?

I tried searching for an answer but found none. Is there a technical reason why methods that use “Extends” must be in a module? The reason I ask is I want to create some extends functions very specific to a certain window, and it would make more sense to contain these methods in that window instead of being global to the entire project. I also may want to use a variation of these methods on different windows, but not have to use different method names (easier code reuse).

So, is there some technical limitation in the IDE or compiler? Or is this just how Xojo designed it?

  1. they have to exist at all times
  2. they have to be global

I believe that’s just how it was designed. Extends are meant to be global. I have tried to do exactly what you want in the past too. Not sure if there’s a Feedback request to allow local extends or not.

[quote=485517:@Norman Palardy]1) they have to exist at all times
2) they have to be global[/quote]
Ok, but why?[quote=485518:@Bob Keeney]Not sure if there’s a Feedback request to allow local extends or not.[/quote]
There’s not (that I found), which is why I was asking here first before submitting a Feedback that won’t be possible.

[quote=485519:@Jay Madren]Ok, but why?
There’s not (that I found), which is why I was asking here first before submitting a Feedback that won’t be possible.[/quote]

As far as I know because they relate to a type and types are global symbols (even if you stuff it in a module etc the compiler looks up and finds it based on the fully qualified name)
Thats based on what I gleaned from years of working with Joe & Aaron and could well be mistaken

You’d really need to ask Joe or Aaron or Mars though
Or Xojo’s current compiler engineer if they’ll reply here about this

how about the use of an interface?
you can share it with some windows,
the method names are the same
and in each method you can do your variation
or call a default method.

Sounds more like you want an interface than an extends
Any window that implements the interface has methods with those signatures but can have different implementations
Basically exactly what you want

Because extends is intended to be available to ALL of the instances of a class.

Wait, what?, you want some methods in a specific to window???, just add normal methods in that particular window and make them public.

If you need in more than one window, just make a Subclass of Window with those aditional methods.

Just add more Subclasses or look into interfaces

and this would also work for any window class but without any benefit.
extends is more for the window base class itself which the other classes inherits.

extends can be used on anything that defines a type
whether its a subclass or base class is irrelevant

First, to everyone, I am only interested in methods that take an “Extends x As String” parameter as I said at the beginning. I’m not trying to extend classes. I don’t want to get into the reason I need them to be extends as opposed to regular methods right now.

The interface option looked promising, but it doesn’t work (gives same error that a local method using extends does - Type “string” has no member named “whatever”).

I’ll just have to use a module.

Thanks.

this IS extending a class though - windows are classes

But as stated you cannot extend some instances of a class one way and some in another
They’d have to actually be difference class types (which you could do as well and then extend those differently)

Interfaces should work for this as well but again you’d need different classes implementing different interfaces to make it work

I’m sure we could make this work the way you wanted

[quote=485605:@Norman Palardy]this IS extending a class though - windows are classes

But as stated you cannot extend some instances of a class one way and some in another
They’d have to actually be difference class types (which you could do as well and then extend those differently)

Interfaces should work for this as well but again you’d need different classes implementing different interfaces to make it work

I’m sure we could make this work the way you wanted[/quote]
I’m not sure you’re understanding my goal. I want to create STRING methods using the EXTENDS parameter option. So I am extending a STRING. But I want this method defined local to a Window, not in a Module. Right now Xojo requires any Method that uses the Extends parameter option to be in a Module.

If you know how to make the Interface paradigm work for this situation, I’m open. But I already tried it and the compiler still balks.

Yeah, I think you will just have to use a regular method in your window. The only downside I see vs extends is that you can’t use dot notation. So you’ll have

MessWithString(s)

or

MessWithString s

instead of

s.MessWithString

Is that a real problem?

[quote=485609:@Jay Madren]I’m not sure you’re understanding my goal. I want to create STRING methods using the EXTENDS parameter option. So I am extending a STRING. But I want this method defined local to a Window, not in a Module. Right now Xojo requires any Method that uses the Extends parameter option to be in a Module.

If you know how to make the Interface paradigm work for this situation, I’m open. But I already tried it and the compiler still balks.[/quote]

OK there’s no way to extend a string locally within the context of JUST one window
The method would apply to ALL strings everywhere - you extend the entire string TYPE everywhere
Its why is says “EXTENDS name AS TYPE” the name is just a handy reference name for the type extension and the code IN that particular method
But you are extending the TYPE - not just one usage of it

Without knowing what it is more specifically you’re tying to do its hard to say how else this might be tackled

You could create your own class that behaves like String, but that seems like a lot of work just to get dot notation :slight_smile:

ahh, the idea is good and you would have methods only in a special scope. (it need a feature request)

your intend is similar to
var x as StringEx
a new class with base class string and u use it where u want.

[quote=485654:@Markus Rauch]ahh, the idea is good and you would have methods only in a special scope. (it need a feature request)

your intend is similar to
var x as StringEx
a new class with base class string and u use it where u want.[/quote]
I logged an enhancement request a while back to implement type alias’s. Maybe this would be another use for them.

I’m not convinced this would be a good idea if it was possible. You want to do something with strings that is somehow specific to a certain window or a subclass of Window, but that window is never referenced – it is a method defined for strings and it seems the window doesn’t even feature as a parameter (if it did the extends method would already be officially specific to that window). Wouldn’t it be much cleaner to define this as a method of that window like Julia suggested? That way you would render the connection to that window explicit. That’s my approach in similar cases.