Showing posts with label encapsulation. Show all posts
Showing posts with label encapsulation. Show all posts

Saturday, June 23

Function groups and now Objects in the new ABAP Objects language

The center of ABAP Objects are Objects. Any object oriented language focuses on objects and hence maps objects with the real world entities. After release 3.1 of SAP WAS ABAP, BOR or the business object repository contains objects. Examples of objects are customers, invoice, order etc. These are contained in the BOR as examples. 


Function Groups and function modules were like objects in ABAP versions before ABAP objects was introduced. Function groups contain function modules. FMs can be treated as services or functions of the objects. Also the global data of function groups formed the attributes of the objects. For example: an FG which processes Sales orders has many FMs within it and global data declared. Global data can be accessed by the FMs within the FG. This ensures encapsulation. The data (global data) and the services (FMs) are combined within a FG.

ABAP programs hold a specific amount of memory art runtime. Similarly when a FM is called, it loads its corresponding FG and global data into memory. One ABAP program can call multiple FMs from several FGs and hence multiple internal ABAP sessions can run and memory occupied. 

As already said, When a FM is called, its FG with global data is loaded into memory. This instance of FG can be treated as Object when we look at this from the Object orientation perspective. So the instance of function group is an interface between the user and function module. Function groups global data can be accessed via function modules only. If Function groups and function modules can be used for object orientation of a program then why ABAP Objects was introduced? The answer is below.

In classical ABAP, a program can work with many instances of different function groups.
But it is not possible to work on many instances of a single function group at a time.
ABAP Objects allow the user to work with many instances of a class.
For example : You are supposed to develop a ABAP program which can process many sales orders at the same time. It is not possible to do so with function groups philosophy. You would instead need a class and several objects of that class. Each object at that time would represent a Sales Order.

So now with the new ABAP objects, you can load multiple instances of the same Class using CREATE OBJECT statement. ABAP accesses the interface of the instance using Object’s reference.

Introduction to Object Orientation


Software systems are defined by data and functionality. In a non object oriented system, functionality and data and treated separately. The focus in such a system remains on functionality. On the other hand, object oriented systems data and functionality are combined together using objects. Objects are concrete representation of real world things. So in a object oriented systems, developer need to map real world things with software objects and they need to define functions a of each object in such a manner that it reflects its behavior in the real world.
Typical objects in a SAP software system can be Invoice, Customer, order etc. It is not possible to introduce Object orientation with this small article.
Objects
Objects are formed out of classes. Class is the structure of object. For example, cuckoo belongs to the bird class, Amazon belongs to the river class. Objects have attributes (also called its characteristics) and functions or services. The services of an object work upon the attributes of the object to change the value of attributes. Attributes and services can be private, public or protected.
Classes
As already described, classes are structure of objects. Any number of objects can be formed out of  a class. Each object has its own values of its attributes.
Object References
Object references are not the real objects but their references. So you can very well access data and services of object using its reference.
Abstraction
The implementation of objects is not visible to the users. Users see only the data and services of the object. But how the services manipulate the data is unknown to the user of the object, such feature is called encapsulation. For example : Tata innova and Maruti are objects of the car class and Average is a service of car class. Average returns different value for both these objects. But how it calculates the average of the car if unknown. User only knows the name of the service, the data it takes and the result it gives.
Inheritance
New classes can be formed from existing classes. This feature of object orientation is called inheritance. The new class thus formed is called derived class. Derived class has data and functions of the parent class. But it can overwrite data and functions of the parent class.
Polymorphism
In ABAP Objects, polymorphism is implemented by redefining methods during inheritance and by using constructs called interfaces. Identical methods behave differently in different classes. Polymorphism means same method behaves differently in different classes.
Polymorphism is a great feature of Object oriented technology. Code written using polymorphism is easy to maintain. With polymorphism, the developer writes a general interface and not a concrete implementation. Change in the requirement of  the client can be handled very easily if the program developed has polymorphism feature  in it.