Tuesday, June 23, 2009

Methods in Components of classes

Methods are internal procedures of a class that determine the behavior of an object. They can access all the attributes of their class and can thus change the object status. Methods have a parameter interface, through which the system passes values to them when they are called, and through which they can return values to the caller. The private attributes of a class can only be changed using methods.

A method meth is declared in the declaration section of a class and in the implementation part of the class using the processing block.

METHOD meth.
...
ENDMETHOD.

You can declare local data types and data objects in methods, just as in all procedures. Methods are called using the CALL METHOD statement or one of its abbreviated forms. You can also call the method dynamically (dynamic invoke).

Instance Methods

Instance methods are declared using the METHODS statement. They can access all the attributes of a class and can trigger all its events.

Static Methods

Static methods are declared using the CLASS-METHODS statement. They can access static attributes of a class and are only allowed to trigger static events.

Constructors

As well as the normal methods that are called using CALL METHOD, there are two special methods called constructor and class_constructor, which are called implicitly when an object is created or when a class component is accessed for the first time.

Functional Methods

Functional methods are methods with any number of IMPORTING parameters and one RETURNING parameter. Functional methods cannot only be called using CALL METHOD. The following expressions can also be used to insert them at operand positions for functions and expressions:

  • Functional method without IMPORTING parameters:

    meth( )
  • Functional method with a non-optional IMPORTING parameter or a number of optional IMPORTING parameters with a preferred parameter:

    meth( f1 )
  • Functional method with IMPORTING parameters:

    meth( p1 = f1 ... pn = fn )

At this operand position it is also possible to link function modules together to make method chains.



No comments:

Blog Archive