This document provides an introduction to object-oriented programming concepts in ABAP, including definitions of objects, classes, inheritance, polymorphism, and encapsulation. It compares procedural and object-oriented programming, and gives examples of common objects like Customer and Order. The document also discusses how ABAP Objects implements these concepts and the advantages of object-oriented design like reusability and reduced maintenance. Methods are introduced as functions that provide business logic within classes.
Introduction and Conceptsof Object Oriented ABAP Vikram Aditya SAP Architect Email: aditya@jhsoftech.com www.jhsoftech.com
2.
What is ObjectOrientation? • In the past, information systems used to be defined primarily by their functionality: data and functions were kept separate and linked together by means of input and output relations. • The object-oriented approach, however, focuses on objects that represent abstract or concrete things of the real world. These objects are first defined by their character and their properties which are represented by their internal structure and their attributes (data). The behaviour of these objects is described by methods (functionality). www.jhsoftech.com
3.
Comparison between Proceduraland Object Oriented Programming • Features Procedure Oriented approach Object Oriented approach Emphasis Emphasis on tasks Emphasis on things that does those tasks. • Modularization Programs are divided into smaller programs known as functions Programs are organized into classes and objects and the functionalities are embedded into methods of a class. Data security Most of the functions share global data Data can be hidden and cannot be accessed by external sources. Extensibility Relatively more time consuming to modify for extending existing functionality. New data and functions can be easily added whenever necessary O www.jhsoftech.com
What is anObject ? • Objects form a capsule which combines the character to the respective behaviour. Objects should enable programmers to map a real problem and its proposed software solution on a one-to-one basis. • Typical objects in a business environment are, for example, ‘Customer’, ‘Order’, or ‘Invoice’. From Release 3.1 onwards, the Business Object Repository (BOR) of SAP Web Applicaton Server ABAP has contained examples of such objects. The BOR object model will be integrated into ABAP Objects in the next Release by migrating the BOR object types to the ABAP class library. www.jhsoftech.com
6.
ABAP Objects • Acomprehensive 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 www.jhsoftech.com
7.
Objects • Objects areinstances of classes. They contain 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 www.jhsoftech.com
8.
Classes • Classes describeobjects. 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 www.jhsoftech.com
9.
Object References • Ina 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: www.jhsoftech.com
10.
Encapsulation • Objects restrictthe 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 www.jhsoftech.com
11.
Inheritance • You canuse 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. www.jhsoftech.com
12.
Polymorphism • Identical (identically-named)methods behave differently in different classes. In ABAP Objects, polymorphism is implemented by redefining methods during inheritance and by using constructs called interfaces www.jhsoftech.com
13.
Uses of ObjectOrientation • 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. www.jhsoftech.com
14.
Uses of ObjectOrientation • 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. www.jhsoftech.com
15.
Object-oriented tools • Object-orientedtools 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 modelling • The object-orientation modelling 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. www.jhsoftech.com
16.
Overview • This sectionof the ABAP User’s Guide provides an overview of the object-oriented extension of the ABAP language. We have used simple examples to demonstrate how to use the new features. However, these are not intended to be a model for object-oriented design. More detailed information about each of the ABAP Objects statements is contained in the keyword documentation in the ABAP Editor. For a comprehensive introduction to object-oriented software development, you should read one or more of the titles listed below. www.jhsoftech.com
17.
Working with classmethods in OOABAP What is a method in a Class ? • Methods are coding blocks of a class, which can provide some business functionality (ex: read material data etc), these methods are similar to Function Modules. • Methods can access all attributes of a class (defined under attributes tab), can access user defined types ( declared under types tab). • The methods can be called using key word CALL METHOD in SAP ABAP programs. Uses of methods in SAP classes? • These methods can be reusable in multiple ABAP programs, a class may contain more than one method. www.jhsoftech.com