Jump to content

Call an object method: Difference between revisions

No edit summary
imported>Acediast
(→‎{{header|COBOL}}: added params)
Line 238:
(. 1 (equals 2)) ; alternative style</syntaxhighlight>
=={{header|COBOL}}==
COBOL added object methods in 2002. It has two ways to invoke a method: the <code>INVOKE</code> statement and inline method invocation.
<syntaxhighlight lang="cobol"> *> INVOKE statements.
INVOKE FooClassmy-class "someMethodsome-method" RETURNING bar *> Factory object
USING BY REFERENCE some-parameter
INVOKE foo-instance "anotherMethod" RETURNING bar *> Instance object
RETURNING foo
 
INVOKE foomy-instance "anotherMethodanother-method" RETURNING bar *> Instance object
*> Inline method invocation
USING BY REFERENCE some-parameter
MOVE FooClass::"someMethod" TO bar *> Factory object
RETURNING foo
MOVE foo-instance::"anotherMethod" TO bar *> Instance object</syntaxhighlight>
 
*> Inline method invocation.
To call factory methods of objects of an unknown type (such as when you may have a subclass of the class wanted), it is necessary to get a reference to the class's factory object by calling the <code>"FactoryObject"</code> method.
MOVE my-class::"some-method"(some-parameter) TO foo
<syntaxhighlight lang="cobol">INVOKE foo-instance "FactoryObject" RETURNING foo-factory
MOVE FooClass::"someMethod" TO bar *> Factory object
*> foo-factory can be treated like a normal object reference.
INVOKE foo-factory "someMethod"</syntaxhighlight>
 
MOVE my-instance::"another-method"(some-parameter) TO foo
MOVE foo-instance::"anotherMethod" TO bar *> Instance object</syntaxhighlight>
 
To call factory methods of objects of an unknown type (such as when you may have a subclass of the class wanted), it is necessary to get a reference to the class's factory object by calling the <code>"FactoryObject"</code> method.
<syntaxhighlight lang="cobol"> INVOKE foosome-instance "FactoryObject" RETURNING foo-factory
*> foo-factory can be treated like a normal object reference.
INVOKE foo-factory "someMethod"</syntaxhighlight>
 
=={{header|CoffeeScript}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.