Question Everardo Cunha · Aug 17, 2020

Cache; Create methods with same name but different parameters

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

Comments

Robert Cemper · Aug 17, 2020

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

0
Everardo Cunha  Aug 17, 2020 to Robert Cemper

Robert,

Thank you so much for your answer!

Stay safe,

Everardo

0
Rubens Silva · Aug 17, 2020

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.

0
Everardo Cunha  Aug 17, 2020 to Rubens Silva

Rubens,

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

Cheers,

Everardo

0
Herman Slagman · Aug 17, 2020

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.

0