Chinaunix首页 | 论坛 | 博客
  • 博客访问: 33277
  • 博文数量: 17
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 190
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 16:20
文章分类
文章存档

2011年(1)

2010年(2)

2009年(3)

2008年(11)

我的朋友

分类:

2008-10-16 15:35:50

what is object orientation?
object orientation,or to be more precise,object-oriented peogranning,is a programing,is a
program-solving method in which the software solution reflects objectd in the real world.
objects:an object is a section of source code that contains data and procides services.
classes   object references   encapsulation   polymorphism     inheritance
classes are templaes for objects.conversely,you can say that the type of an object is the
same an its class. a class id an abstract desctription of an object.
defining local classes
CLASS DEFINITION.
..
ENDCLASS.
if you declare methods in the declaration part of a class,you must also write an
implementation part for it.
CLASS IMPLEMENTATION.
..
ENDCLASS.
METHOD .
...
ENDMETHOD.
you call methods using the CALL METHOD statement.
visibiluty sections
CLASS DEFINITION.
 PUBLIC SECTION
....
PROTECTED SECTION.
...
PRIVATE SECTION.
...
ENDCLASS.
classes introductory example:
CLASS C_COUNTER DEFINITION.
PUBLIC SECTION.
METHODS: SET_COUNTER IMPORTING VALUE(SET_VALUE) TYPE I,
         INCREMENT_COUNTER,
         GET_COUNTER EXPORTING VALUE(GET_VALUE) TYPE I.
PRIVATE SECTION.
  DATA COUNT TYPE I.
ENDCLASS.
CLASS C_COUNTER IMPLEMENTATION.
  METHOD SET_COUNTER.
   COUNT = SET_VALUE.
  ENDMETHOD.
  METHOD INCREMENT_COUNTER.
    ADD 1 TO COUNT.
   ENDMETHOD.
  METHOD GET_COUNTER.
   GET_VALUE = COUNT.
  ENDMETHOD.
ENDCLASS.
you define class references using the
... TYPE RET TO
you can create an object using the statement
CREATE OBJEST .
you can declare methods in the declaration part of a class or in an interface. to declare
instance methods,use the folloeing statement:
METHODS IMPORTING..[VALUE] TYPE type [OPTIONAL].
             EXPORTING..[VALUE] TYPE type [OPTIONAL].
             CHANGING..[VALUE] TYPE type [OPTIONAL].
             RETURNING VALUE().
             EXCEPTIONS...
to declare static methods,use the following statement:
CLASS-METHODS ..
CLASS DEFINITION INHERITING FROM .
defining interfaces
INTERFACE .
....
ENDINTERFACE.
to implement an interface in a class,use the statement:
INTERFACES .
you declare events in the declaration part of a  class or in an interface.to declare
instance events,use the following statement:
EVENTS EXPORTING... VALUE() TYPE type [OPTIONAL].
to declare static events,use the following statement:
CLASS-EVENTS ...
to trigger an event in a method,use the following statement:
RAISE EVENT EXPORTING...
TO declare an event handler method, use the following statement:
METHODS FOR EVENT OF IMPORTING..
Events:Introductory example:
REPORT demo_class_counter_event.
CLASS counter DEFINITION.
  PUBLIC SECTION.
    METHODS increment_counter.
    EVENTS  critical_value EXPORTING value(excess) TYPE i.
  PRIVATE SECTION.
    DATA: count     TYPE i,
          threshold TYPE i VALUE 10.
ENDCLASS.
CLASS counter IMPLEMENTATION.
  METHOD increment_counter.
    DATA diff TYPE i.
    ADD 1 TO count.
    IF count > threshold.
      diff = count - threshold.
      RAISE EVENT critical_value EXPORTING excess = diff.
    ENDIF.
  ENDMETHOD.
ENDCLASS.
CLASS handler DEFINITION.
  PUBLIC SECTION.
    METHODS handle_excess
            FOR EVENT critical_value OF counter
            IMPORTING excess.
ENDCLASS.
CLASS handler IMPLEMENTATION.
  METHOD handle_excess.
    WRITE: / 'Excess is', excess.
  ENDMETHOD.
ENDCLASS.
DATA: r1 TYPE REF TO counter,
      h1 TYPE REF TO handler.
START-OF-SELECTION.
  CREATE OBJECT: r1, h1.
  SET HANDLER h1->handle_excess FOR ALL INSTANCES.
  DO 20 TIMES.
    CALL METHOD r1->increment_counter.
  ENDDO.
 
阅读(787) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~