ABAP OO笔记2

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值