ABAP OO笔记2

来源:互联网 发布:mac os x 更新失败 编辑:程序博客网 时间:2024/06/10 17:32

2008-9-2

22.       Methods that have a RETURNING parameter are described as functional methods. These methods cannot have EXPORTING or CHANGING parameters, but has many (or as few) IMPORTING parameters and EXCEPTIONS as required.

23.       Functional methods can be used directly in various expressions.

24.       Methods: tempa

             Importing a type ty_distance

                        Returning b type ty_fuel.

         The syntax for instance methods (analogous to static methods) is as follows, depending on the number of IMPORTING parameters:

         No IMPORTING parameter:  ref->tempa()

         Exactly 1 IMPORTING parameter:  ref->tempa( p1 ) or ref->tempa( a = p1 )

         Several IMPORTING parameters:  ref->tempa( a1 = p1 a2 = p2 )

25.       Constructor

The constructor is a special (instance) method in a class and is always named CONSTRUCTOR. The following rules apply:

a)         Each class has exactly one constructor

b)         The constructor does not need to be defined if no implementation is defined.

c)         The constructor is automatically called during runtime within the CREATE OBJECT statement.

d)         If you need to implement the constructor, then you must define and implement it in the PUBLIC SECTION. When EXCEPTIONS are triggered in the constructor, instances are not created, so no main memory space is taken up.

e)         Only has IMPORTING parameters and EXCEPTIONS.

f)          Is executed exactly once per instance.

g)         Most used to initialize and modify static attributes.

26.       Static Constructor

The static constructor is a special static method in a class and is always named CLASS_CONSTRUCTOR. It is executed precisely once per program. The static constructor of class <classname> is called automatically before the class is first accessed, that is, before any of the following actions are executed:

a)         Creating an instance in the class using CREATE OBJECT obj, where obj has the data type REF TO <classname>.

b)         Addressing a static attribute using <classname>=><an_attribute>.

c)         Calling a static attribute using CALL_METHOD <classname>=><a_classmethod>.

d)         Registering a static event handler method using SET HANDLER <classname>=><handler_method> for obj.

e)         Registering an event handler method for a static event in class <classname>.

f)          Automatically called before the class is first accessed.

27.       In delegation, two objects are involved in handling a request: then recipient of the reques delegates the execution of the request to a delegate.

28.       There is a local namespace within methods. Definitions of variables can cover components in one class.

29.       You can address the object itself within object methods using the implicitly available reference variable ME.

For example:

           In the CONSTRUCTOR, then instance attribute name is covered by the locally defined variable name. in order to still be able to address the instance attribute, you need to use ME.

原创粉丝点击