Wednesday, 18 July 2012

Polymorphism

class lcl_car DEFINITION.

PUBLIC SECTION.

METHODS: car, " method use for operation
         color.

ENDCLASS.

CLASS lcl_car IMPLEMENTATION.

METHOD: car.

  write :/ 'Plz select the new car'" Method implementation

  ENDMETHOD.

METHODcolor.

       write:/ 'The selecting car color is ' COLOR 4.

  ENDMETHOD.
  ENDCLASS.


class lci_car DEFINITION INHERITING FROM lcl_car.

PUBLIC SECTION.

  METHODs: car REDEFINITION"method  car is overriding
  ENDCLASS.

  CLASS lci_car IMPLEMENTATION.

  METHOD: car.
    CALL METHOD super->car.           " calling the base class using the super class.
    write: / 'The selected car is ford',
           / 'Do u like it'.

    ENDMETHOD.
    ENDCLASS.

load-OF-PROGRAM.
    data: lcl TYPE REF TO lci_car.
    create OBJECT: lcl.

    call METHOD: lcl->car,
                 lcl->color.

Monday, 16 July 2012

INTERFACE inter1.

  EVENTS: event1."event decleration

  methods: method1 FOR EVENT event1 of inter1.
 ENDINTERFACE.


INTERFACE inter2 .
  INTERFACEs inter1 .
methods: method2,
                 method3.

  ENDINTERFACE.

CLASS inte DEFINITION.
 PUBLIC SECTION.




 INTERFACEs inter2.
 CLASS-data: a TYPE i VALUE 10.
  CLASS-data: b TYPE i VALUE 20.
 ENDCLASS.



CLASS inte IMPLEMENTATION.

METHOD: inter1~method1.                               "implementing the event here
    write:/ 'The value of I is' , a COLOR 5.

    ENDMETHOD.

METHOD inter2~method2.

  write:/ 'The value of i is ' ,b COLOR 6.

  ENDMETHOD.

method inter2~method3.

  write:/ 'The value of i is ', a COLOR 7.
 RAISE EVENT inter1~event1.    "Raising the event
  ENDMETHOD.




  ENDCLASS.

START-OF-SELECTION.

DATA: obj TYPE REF TO inte.
  create OBJECT: obj .
SET HANDLER obj->inter1~method1 FOR obj.

    CALL METHOD"obj->inter1~method1,
               obj->inter2~method2,
               obj->inter2~method3.

INTERFACE WITH ALIASES IN OOPS

INTERFACE inter1.
  METHODs:show.
  ENDINTERFACE.


INTERFACE inter2.
  INTERFACEs:inter1.
   ALIASES show3 for inter1~SHOW.

  ENDINTERFACE.


class cls DEFINITION.
  PUBLIC SECTION.
  INTERFACEs: inter2.
   ALIASES: show1 FOR inter1~show,
            show2 for inter1~show,
            I_SHOW3 FOR INTER2~SHOW3.
  ENDCLASS.

  class cls IMPLEMENTATION.
 
   METHOD : inter1~show.

     write:/ ' the method use for aliase'.
     ENDMETHOD.
*        METHOD :inter2~show1.
*
*     write:/ ' the method use for aliase'.
*     ENDMETHOD.
   ENDCLASS.

 START-OF-SELECTION.
   DATAin TYPE REF TO cls.
   CREATE OBJECT in.
   CALL METHOD : in->show1,
                 in->show2,
                 IN->I_show3.

Friday, 13 July 2012

Me usage

class q1 DEFINITION.
 PUBLIC SECTION.
data: a TYPE i VALUE 10.   <-------me->a
 METHODs:constructor.
 ENDCLASS.

 CLASS q1 IMPLEMENTATION.
   METHOD: constructor.
     data: a TYPE i value 20.
     write:/ ' The Value of class is', me->a ,
             /  ' The value of class is ',a .
     ENDMETHOD.
     ENDCLASS.

     START-OF-SELECTION.


     data obj TYPE REF TO q1.
      CREATE OBJECT obj.

Final keyword.

Final keyword.......








class b1 DEFINITION ABSTRACT.
  PUBLIC SECTION.
  methods:constructor.
  ENDCLASS.

  class b2 DEFINITION INHERITING FROM b1  .
   PUBLIC SECTION.
   methods:constructor.
    ENDCLASS.


 class b3 DEFINITION INHERITING FROM b2 FINAL.
  PUBLIC SECTION.
  METHODs: constructor.

   ENDCLASS.



class b1 IMPLEMENTATION.
  METHOD: constructor.
    write:/ 'constuctor with abstract class'.
    ENDMETHOD.
    ENDCLASS.
    class b2 IMPLEMENTATION.
     METHOD:constructor.
       CALL METHOD super->constructor.

       WRITE :/ 'constructor abstract class and super keyword'.
       ENDMETHOD.
     ENDCLASS.

 class b3 IMPLEMENTATION.
  METHOD:constructor.
     CALL METHOD super->constructor.
    WRITE:/ 'Use of final keyword'.
    ENDMETHOD.
    ENDCLASS.
    START-OF-SELECTION.
    DATA: obj TYPE REF TO b3.
    create OBJECT obj.

Thursday, 12 July 2012

abstract class

Abstract class with constructor and super keyword..






class b1 DEFINITION ABSTRACT.
  PUBLIC SECTION.
  methods:constructor.
  ENDCLASS.

  class b2 DEFINITION INHERITING FROM b1.
   PUBLIC SECTION.
   methods:constructor.
    ENDCLASS.

class b1 IMPLEMENTATION.
  METHOD: constructor.
    write:/ 'constuctor with abstract class'.
    ENDMETHOD.
    ENDCLASS.
    class b2 IMPLEMENTATION.
     METHOD:constructor.
       CALL METHOD super->constructor.

       WRITE :/ 'constructor abstract class and super keyword'.
       ENDMETHOD.
     ENDCLASS.
    START-OF-SELECTION.
    DATA: obj TYPE REF TO b2.
    create OBJECT obj.