21.03.2013 Views

Object Oriented ABAP

Object Oriented ABAP

Object Oriented ABAP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1.6 Inheritance<br />

In OO <strong>ABAP</strong> we use an existing class to derive a new class (child class). The new class<br />

contains the attributes of the parent class (derives according to the visibility of attributes<br />

and methods) in addition to new attributes and methods added to it. The child class derives<br />

all the attributes and methods declared in parent class as public visibility. The child class<br />

cannot inherit private members. The protected members in parent class are derived in child<br />

class but their visibility changes to private.<br />

1.7 Interfaces<br />

Interfaces are similarly defined as classes. They also contain attributes and methods. But<br />

interfaces do not have implementation part. Their methods are implemented in the class<br />

that implements the interface.<br />

So we provide different implementation to the methods defined in the interface in different<br />

class that implements that interface. This way polymorphism is achieved.<br />

1.8 Binding in <strong>Object</strong> <strong>Oriented</strong> languages<br />

It is the concept which determines the object‟s method to be invoked based on the<br />

signature or parameters provided. It is important in case of invoking a method, which is<br />

redefined in subsequent sub classes. As the level of hierarchy increases and the same<br />

method is redefined in subclasses we need to know which method is called. When this<br />

decision is made at run time it is called as Dynamic binding. When this decision is made at<br />

compile time it is known as Static binding. In Java this concept is implemented using<br />

concept of method overriding and in C++ there is concept of virtual functions. They help in<br />

achieving dynamic binding. Similarly in OO <strong>ABAP</strong> we can redefine methods and use concept<br />

of binding to invoke methods as per required.<br />

Binding in OO <strong>ABAP</strong><br />

Suppose we need to redefine or override a method of a class in all sub classes inheriting<br />

from it. We can take a pointer or reference variable to the base or parent class. This parent<br />

class reference variable can take or refer to objects of the sub classes. Now to decide that<br />

which method will be called upon while we are using this parent class reference variable, we<br />

need to know about the concept of binding.<br />

We define a reference variable as<br />

Data : obj_a type ref to .<br />

Here obj_a is a reference variable of type class <br />

Creating the object<br />

create object : obj_a.<br />

Now obj_a refers to an object of class

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!