Question Kishan Ravindran · Dec 26, 2017

What is difference between using a command $classmethod rather than just invoking them straight away?

What is difference between using a command $classmethod rather than just invoking them straight away?

For example if i need to call a class and its method i can just use like

do ##class(circle).radius()

rather than using

do $classmethod("circle",radius)

(I suppose both of them doing the same function i am not aware of it)

Please help me understand what is different and is there any specific usage.

Correct me if i have made mistake.

Comments

Kishan Ravindran  Dec 26, 2017 to Robert Cemper

So can this is be used in a parent-child class format if how will this be of use. And by using $classmethod this is there any advantage, if so can you mention some.

Thanks

Kishan R

0
Vitaliy Serdtsev · Dec 26, 2017

The key difference of $classmethod is runtime:

$CLASSMETHOD permits a ObjectScript program to invoke an arbitrary class method in an arbitrary class. Both the class name and the method name may be computed at runtime or supplied as string constants.proof
0
Eduard Lebedyuk · Dec 26, 2017

If you can, always invoke code directly:

do ##class(circle).radius()

Use classmethod only if you can't invoke method directly.

0
Evgeny Shvarov · Dec 26, 2017

How to call a classmethod?

If you are inside the class Circle call it with:

do ..Radius()

If you call this method from another class use:

do ##class(Circle).Radius()

But there are cases when you do not know either name of a class or name of a method on runtime. So $classmethod is your friend here:

do $classmethod("Circle","Radius")

HTH

0
Guilherme Silva · Dec 27, 2017

I think in case you need to call a lot of methods in programatic mode, you can do it this way, btw is easier. 

0