RosettaCodeData/Task/Respond-to-an-unknown-method-call/Cache-ObjectScript/respond-to-an-unknown-method-call.cos
Ingy döt Net 6f050a029e update
2013-06-05 21:47:54 +00:00

33 lines
501 B
Text

Class DynamicDispatch.Example Extends %RegisteredObject
{
Method Foo()
{
Write "This is foo", !
}
Method Bar()
{
Write "This is bar", !
}
Method %DispatchMethod(Method As %String, Args...)
{
Write "Tried to handle unknown method '"_Method_"'"
For i=1:1:$Get(Args) {
Write ", " If i=1 Write "with arguments: "
Write "'"_Args(i)_"'"
}
Write !
}
ClassMethod Test()
{
Set obj=##class(DynamicDispatch.Example).%New()
Do obj.Foo()
Do obj.Bar()
Do obj.Grill()
Do obj.Ding("Dong", 11)
}
}