This article discusses ABAP Objects, also known as OOABAP ( Object Oriented ABAP ) and Object Orientation, i.e., Object-Oriented Programming model.
ABAP OBJECTS ( OBJECT-ORIENTED ABAP )
ABAP started as a procedural programming language. With time, object-oriented features were added to ABAP, and it evolved into an object-oriented programming language. ABAP Objects is Object-oriented extension of ABAP.
Thus, OOPS ABAP or ABAP Objects or Object Oriented ABAP represents the object-oriented features added to ABAP. Thus, ABAP Objects is procedural ABAP plus Object-oriented ABAP. ABAP Objects is the complete set of ABAP programming elements.
Object-oriented ABAP is fully compatible with structured ABAP. We can use ABAP Objects in existing programs and can use “conventional” ABAP in new ABAP Objects programs i.e. both can be used in same program.
Adding OO features to ABAP was important as latest application developments rely on object-oriented approach and ABAP was thoughtfully extended to Object Orientation. To truly appreciate the object-oriented programming model, we must understand the difference between procedural and object-oriented programming models.
ABAP OBJECTS IS COMPATIBLE EXTENSION OF ABAP
- ABAP Object statements can be used in procedural ABAP programs
- Class implementation can contain procedural ABAP statements.
Object-oriented concepts of ABAP Objects are inspired by other object-oriented programming languages such as C++ or Java. Despite that, ABAP Objects guarantees compatibility with procedural ABAP language elements, and an ABAP developer can use both together in a single ABAP program.
PROCEDURAL PROGRAMMING MODEL
The above image explains the procedural programming model clearly. The usual process of working with a procedural programming model is to define separate data and functions. Thus procedural programming does not by default support encapsulate data.
A procedural program declares a set of global variables which are accessible from any part of the program. The functions are modularized using subroutines or function modules with complete access to all global variables.
In procedural ABAP program, we start with type definitions and global data declarations. The main program holds the logic which might be encapsulated in subroutines or function modules. The global data remains unprotected and can be read and changed from anywhere in the program.
Thus, a procedural program is more procedure-oriented than data-oriented, and it has little or no protection for global data objects.
Another significant limitation of the procedural programming model is it does not support multiple instantiations. If you have to maintain numerous instances in procedural programming, then it will require considerable programming effort.
PROCEDURAL PROGRAMMING DISADVANTAGES
Does not have encapsulated data and services.
Global variables of ABAP Programs can be accessed from any part of the program. This leads to un-protected data objects.
Does not support multiple instantiation.
WHAT IS OBJECT ORIENTATION
Object-orientation or object-oriented programming is a methodology of problem-solving in which a software model reflects or imitates a real-world thing. As it is easy to understand real-world objects, an object-oriented software solution is considered an easier to understand software solution when compared to a procedural programming model.
Another goal of object orientation is to unify data and functions in object models. For example, in a procedural programming language, data and procedures are stored at a different place, and procedures are designed to access and work with the data.
Object-oriented programming supports multiple instantiations. Creating several runtime instances using the same program context is one of the significant characteristics of object-oriented programming.
Encapsulation using objects has following features : (1) objects encapsulate functions and data (2) create multiple instances, each instance have their own separate data area, which keeps the data protected.
Objects created are stored in program’s internal memory.
OBJECT-ORIENTATION IS DIRECT ABSTRACTION OF A REAL OBJECT
The above diagram explains this concept very clearly. Object-orientation follows the approach of abstracting real-objects. For each real object, like building, human, car, we can create classes to holds its characteristics and functions in a unified fashion. Instance of this class gives distinct objects.
ADVANTAGES OF OBJECT-ORIENTED PROGRAMMING
Easy to understand – Object-oriented models are easier to understand as they replicate a real-world object.
Reduced Maintenance Effort: In a well-designed object-oriented system, it should be possible to implement changes at the class level without making alterations at other points in the system.
Reusable components: Through polymorphism and inheritance, object-oriented programming allows to reuse individual components of a class.
Design phase advantage: Object-oriented system follows SDLC wherein many problems and bugs can be detected and rectified at the design phase itself.
CLASS and OBJECTS
The concept of classes and objects is the foundation of object-oriented programming. The real world is made up of objects, for example building, car, human and so on. Placing all the characteristics and behaviors of an object type into a class is knows an defining the class. Thus when defining a car class, we place all the common characteristics of a car into the car class, for example a car will have wheels, a car will have an engine, a car will have seats, etc, etc. Using this car class, individual car objects can be derived.
Class forms the blueprint or template for objects. A class encapsulates data (also known as attributes) and services (also known as methods) into a single unit.
Objects are runtime instances of a class. Several runtime instances can be created based on a single class. Each instance (object) of a class has a unique identity and its own set of values for its attributes.
3 PILLARS OF OBJECT ORIENTED PROGRAMMING
Encapsulation – Restricts the visibility of object resources ( attributes (data ) and methods (services) ) to other users. In object-oriented, both data and services are encapsulated and not visible outside the object itself. The methods or services work like an object interface through which other objects can interact with it.
Inheritance – Derive a new class ( also known as subclass or child class ) from an existing class ( also known as the superclass or parent class ). The derived class inherits the data and method of the superclass and can also add its own data and methods.
Polymorphism – Methods with identical names performing different functionality in different classes. In ABAP Objects, polymorphism is achieved by redefining methods during inheritance or by implementing interface methods. Polymorphism supports generic programming.
Object oriented ABAP supports Event Control – Objects can trigger events. Event triggered makes other object respond to the event.
OBJECT-ORIENTED PROGRAMMING AND SOFTWARE DEVELOPMENT PROCESS
It is recommended to use modelling tools for analysis and design of software solutions. In object-oriented programming, analysis and design decisions greatly impact the implementation.
SUMMARIZED KEY CHARACTERISTICS OF OBJECT-ORIENTATION IN ABAP
- with Objects you achieve a direct abstraction of the real world object
- Objects encapsulate data and functions into a single unit
- Provides superior process implementation methodology compared to procedural programming.