Cache; Create methods with same name but different parameters

Primary tabs

Greetings,

Since cache is an OOP language, how can I create 2 methods with the same name but different parameters? Right now when I try that I get a compile time error!

Element name conflict [80670005] : Method mymethod

Thank you,

Everardo

 

 

Replies

it is not possible within the same class as you break the uniqueness of names.

But if you have class A1 with Method MX(....)  
you can create class A2 Extends A1 and overload Method MX as you like or need.
You still can call MX of class A1 from class A2 using ##super()

All with the assumption that neither class A1 nor Method MX is FINAL

Robert,

Thank you so much for your answer!

Stay safe,

Everardo

Currently ObjectScript doesn't support method override. But you might be able to simulate it by using rest parameters and delegating to a second private method that handles it according to what has been provided to the initial method.

EDIT: Whoops! I meant overload.

Rubens,

I was trying to avoid that since I wanted to leave the original method untouched! Anyway, thank you so much!

Cheers,

Everardo

Method (or Function) overloading isn't necessarily an OOP-thing.
Many programming languages only allow a constructor to have the name of the class itself.
In COS you can have many constructors with different names and signatures, so overloading isn't really needed.