Question
· 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.

Discussion (7)0
Log in or sign up to continue

the key difference is that you can pass the classname by a variable.
So you are prepared to get the classname passed by some other method.

In your example with a constant string"circle"you miss the key advantage and It's of o added value.

BTW. Correct is   $classmethod("circle.radius","%New")

http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...

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