Jump to content

Call an object method: Difference between revisions

→‎{{header|COBOL}}: switched to free format
imported>Acediast
(→‎{{header|COBOL}}: added params)
imported>Acediast
(→‎{{header|COBOL}}: switched to free format)
Line 238:
(. 1 (equals 2)) ; alternative style</syntaxhighlight>
=={{header|COBOL}}==
{{Works with|COBOL 2002}}
COBOLThere added object methods in 2002. It hasare two ways to invoke a method: the <code>INVOKE</code> statement and inline method invocation.
<syntaxhighlight lang="cobolcobolfree"> *> INVOKE statements.
INVOKE my-class "some-method" *> Factory object
USING BY REFERENCE some-parameter
RETURNING foo
INVOKE my-instance "another-method" *> Instance object
USING BY REFERENCE some-parameter
RETURNING foo
 
*> Inline method invocation.
INVOKE my-instance "another-method" *> Instance object
MOVE my-class::"some-method"(some-parameter) TO foo *> Factory object
USING BY REFERENCE some-parameter
MOVE my-instance::"another-method"(some-parameter) TO foo *> Instance object</syntaxhighlight>
RETURNING foo
 
*> Inline method invocation.
MOVE my-class::"some-method"(some-parameter) TO foo
*> Factory object
 
MOVE my-instance::"another-method"(some-parameter) TO foo
*> 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="cobolcobolfree"> INVOKE some-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.