Table of Contents
Object Oriented ABAP or OOABAP is the object-oriented extension of ABAP, which mainly focuses on the object rather than the code flow. An object-oriented approach enables programmers to think like they are working with real-life entities.
Just take a real-life scenario, a person having knowledge can do various works, same in oops, object have fields to store data and with which it can do various works.
The Object-Oriented concept of ABAP mainly revolves around the classes and object, which are the basic elements of OOABAP.
Before moving further, let’s learn about the very basic and the most important elements of OABAP:
It’s a working entity of a class. Each object is unique at its own, meaning with unique identity and attributes. Attributes defines the state of an object whereas behavior of an object refers to the changes that occur in its attributes over a period of time. An object can be associated with the class by declaring it with the same data type as of the class within which an object has been created.
An object has three characteristics –
- Has a state.
- Has unique identity.
- May or may not display behavior.
A class is like a blueprint of an object or a template that binds similar kind of data. It defines the characteristics of an object. Following are the components of class:
- Attribute – variables or constant declared within the class and can be access by all the methods of that class.
- Method – Determines the behavior of an object, it provide some functionality. A method can access all the attributes of their class.
- Events – A mechanism through which one method can raise method of another class.
- Interface – Independent structure which are used in a class to extend functionality of a class.
- Alias – A concept of providing alternate method name for interface method in an implemented class.
Component types of class:
- Instance Component (instance attributes, instance methods & instance events) – These components can only be addressed by the instance(object) of that class only.
- Static Component (static attributes, static method & static events) – These components can be used independently of a class instance.
The three pillars of OOABAP (Advance elements of OOABAP):
- Encapsulation: It is a concept of preventing your data from being arbitrarily accessed by some other outside interference or protect your data from being misused. It Allows us to bind similar kind of data in one unit. It restricts the visibility of components of class.
There are 3 levels of visibility:
- Private – Components will be visible to that class only, where they are defined.
- Protected – Components will be visible to that class, where they are defined and to the inherited class.
- Public – Components with this visibility will be available to all.
- Polymorphism: A concept which allows to overwrite some functionality. That is, a same functionality of a class (i.e., method) can be reused in other classes with some enhancement in it.
‘Interface’ is a concept in object-oriented ABAP to achieve polymorphism. An interface is a place where a functionality(method) can be defined with some parameters, which later can have different implementations in different classes.
Advantage of polymorphism is that we don’t need to define a method for different scenarios of implementation. Same definition can be used for different implementations.
- Inheritance: A name itself explaining the concept, i.e., it allows a sub class or a child class to inherit the properties from a parent class. In OOABAP, only single and multilevel inheritance is allowed.
Single inheritance means only one parent class and its child class.
Multilevel Inheritance means a parent class can have a child class, it grandchild class and so on with the hierarchy.
The main advantage of inheritance is reusability of code functionality & fast implementation time.
Advantages of OOPS Concept in ABAP:
- In OOABAP, programs are divided into objects leading to better and powerful data management.
- Provide properties like data hiding(encapsulation) & code reusability(inheritance) with more data security.
- Better performance with less consumption of time.
- Helps in future orientation.
- Simple and it much easier to maintain as compare to procedural ABAP programming.
- Relatively flexible & adaptable to changing business needs.
- Object Oriented programming languages include features such as “Class”, “Instance”, “Inheritance” and “Polymorphism” that increase the power and flexibility of an object.