Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

OO programming

Former Member
0 Likes
763

Hello

Can any one give me good examples on methods and events used in OO ABAP and how or in what way OO ABAP diffrent from Procedural ABAP

Points for sure

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
721

Hi,

Give me your mail id, i will send Documentation.

Thanks,

Anitha

7 REPLIES 7
Read only

Former Member
0 Likes
722

Hi,

Give me your mail id, i will send Documentation.

Thanks,

Anitha

Read only

Former Member
0 Likes
721

Hi,

Object orientation (OO), or to be more precise, object-oriented programming, is a problem-solving method in which the software solution reflects objects in the real world.

A comprehensive introduction to object orientation as a whole would go far beyond the limits of this introduction to ABAP Objects. This documentation introduces a selection of terms that are used universally in object orientation and also occur in ABAP Objects. In subsequent sections, it goes on to discuss in more detail how these terms are used in ABAP Objects. The end of this section contains a list of further reading, with a selection of titles about object orientation.

Objects

An object is a section of source code that contains data and provides services. The data forms the attributes of the object. The services are known as methods (also known as operations or functions). Typically, methods operate on private data (the attributes, or state of the object), which is only visible to the methods of the object. Thus the attributes of an object cannot be changed directly by the user, but only by the methods of the object. This guarantees the internal consistency of the object.

Classes

Classes describe objects. From a technical point of view, objects are runtime instances of a class. In theory, you can create any number of objects based on a single class. Each instance (object) of a class has a unique identity and its own set of values for its attributes.

Object References

In a program, you identify and address objects using unique object references. Object references allow you to access the attributes and methods of an object.

In object-oriented programming, objects usually have the following properties:

Encapsulation

Objects restrict the visibility of their resources (attributes and methods) to other users. Every object has an interface, which determines how other objects can interact with it. The implementation of the object is encapsulated, that is, invisible outside the object itself.

Polymorphism

Identical (identically-named) methods behave differently in different classes. Object-oriented programming contains constructions called interfaces. They enable you to address methods with the same name in different objects. Although the form of address is always the same, the implementation of the method is specific to a particular class.

Inheritance

You can use an existing class to derive a new class. Derived classes inherit the data and methods of the superclass. However, they can overwrite existing methods, and also add new ones.

Uses of Object Orientation

Below are some of the advantages of object-oriented programming:

Complex software systems become easier to understand, since object-oriented structuring provides a closer representation of reality than other programming techniques.

In a well-designed object-oriented system, it should be possible to implement changes at class level, without having to make alterations at other points in the system. This reduces the overall amount of maintenance required.

Through polymorphism and inheritance, object-oriented programming allows you to reuse individual components.

In an object-oriented system, the amount of work involved in revising and maintaining the system is reduced, since many problems can be detected and corrected in the design phase.

Achieving these goals requires:

Object-oriented programming languages

Object-oriented programming techniques do not necessarily depend on object-oriented programming languages. However, the efficiency of object-oriented programming depends directly on how object-oriented language techniques are implemented in the system kernel.

Object-oriented tools

Object-oriented tools allow you to create object-oriented programs in object-oriented languages. They allow you to model and store development objects and the relationships between them.

Object-oriented modeling

The object-orientation modeling of a software system is the most important, most time-consuming, and most difficult requirement for attaining the above goals. Object-oriented design involves more than just object-oriented programming, and provides logical advantages that are independent of the actual implementation.

Check out the links

http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm

Regards,

Kate

Read only

Former Member
0 Likes
721

Hello Anitha

Thx for the reply my id is prashanth.abap@hotmail.com.

Read only

0 Likes
721

Hi,

Please Check your mail Id and Reward Points if helpful.

Thanks,

Anitha

Read only

Former Member
0 Likes
721

hi,

Object orientation (OO), or to be more precise, object-oriented programming, is a problem-solving method in which the software solution reflects objects in the real world.

1) code reuasbility

2) east to handle programms

3) easy to handle exceptions

4) it provide polymorphism

5) we can easly handle memory management issues

<b>Objects</b>

An object is a section of source code that contains data and provides services. The data forms the attributes of the object. The services are known as methods (also known as operations or functions). Typically, methods operate on private data (the attributes, or state of the object), which is only visible to the methods of the object. Thus the attributes of an object cannot be changed directly by the user, but only by the methods of the object. This guarantees the internal consistency of the object.

<b>Classes</b>

Classes describe objects. From a technical point of view, objects are runtime instances of a class. In theory, you can create any number of objects based on a single class. Each instance (object) of a class has a unique identity and its own set of values for its attributes.

<b>Object References</b>

In a program, you identify and address objects using unique object references. Object references allow you to access the attributes and methods of an object.

In object-oriented programming, objects usually have the following properties:

<b>Encapsulation</b>

Objects restrict the visibility of their resources (attributes and methods) to other users. Every object has an interface, which determines how other objects can interact with it. The implementation of the object is encapsulated, that is, invisible outside the object itself.

<b>Polymorphism</b>

Identical (identically-named) methods behave differently in different classes. Object-oriented programming contains constructions called interfaces. They enable you to address methods with the same name in different objects. Although the form of address is always the same, the implementation of the method is specific to a particular class.

<b>Inheritance</b>

You can use an existing class to derive a new class. Derived classes inherit the data and methods of the superclass. However, they can overwrite existing methods, and also add new ones.

<b>Uses of Object Orientation</b>

Below are some of the advantages of object-oriented programming:

1) Complex software systems become easier to understand, since object-oriented structuring provides a closer representation of reality than other programming techniques.

2) In a well-designed object-oriented system, it should be possible to implement changes at class level, without having to make alterations at other points in the system. This reduces the overall amount of maintenance required.

3) Through polymorphism and inheritance, object-oriented programming allows you to reuse individual components.

4) In an object-oriented system, the amount of work involved in revising and maintaining the system is reduced, since many problems can be detected and corrected in the design phase.

all these features are not avilable in procedural programming language.

<b>SAMPLE PRGRAM</b>

CLASS C_COUNTER DEFINITION.

  PUBLIC SECTION.
            obj TYPE REF TO C_COUNTER DEFINITION. " REFAREVCE VARIABLE
    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.
    write:/ 'the value is', GET_VALUE.
  ENDMETHOD.

ENDCLASS.


**** procedure creating object to the class
      CREATE OBJECT obj.
****procedure to calling the methods of the class.
    CALL METHOD obj-->GET_COUNTER.

<b>sample program for handling events</b>

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.

<u><b>Follow this link for more information.</b></u>

http://help.sap.com/saphelp_nw2004s/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/webcontent/uuid/35eaef9c-0b01-0010-dd8b-e3b0f... [original link is broken]

regards,

Ashokreddy

Read only

Former Member
0 Likes
721

hi,

i sent some materal and examples to ur id.

if helpful reward points.

Read only

jayanthi_jayaraman
Active Contributor