2. Object-Oriented Programming is a methodology or
paradigm to design a program using classes and
objects. It simplifies the software development and
maintenance by providing some concepts:
1. Class
2. Object
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation
3. CLASS
A class is a user defined data type with attributes,
methods, events, user-defined types, interfaces etc
for a particular entity or business application.
4. COMPONENTS OF A CLASS
Attributes: Attributes are variables, constants declared within
a class .
Methods: Methods are coding blocks which provides some
functionality .
These methods are similar to Function Modules in ABAP.
Methods can access all attributes of it`s own class.
Methods are defined in definition part and implemented in
implementation part.
We can call methods using CALL METHOD statement.
Events: Event is a mechanism through which one method of
a class can raise method of other class, without hazard of
instantiating that class.
Interfaces: Interfaces are similar to classes which contain
methods Without any implementation.
Interfaces are mainly used to extend the scope or functionality
of the class.
5. INSTANCE AND STATIC COMPONENTS
Instance components : These components exist
separately in each instance (object) of the class
and are referred using instance component selector
using ->
Static components : These components exists
globally for a class and are referred to using static
component selector => .
6. VISIBILITY OF COMPONENTS OF CLASS
Public section: Data declared in public section can
be accessed by the class itself, by its subclasses as
well as by other users outside the class.
Protected section: Data declared in the protected
section can be accessed by the class itself, and
also by its subclasses but not by external users
outside the class.
Private Section: Data declared in the private
section can be accessed by the class only, but not
by its subclasses and by external users outside the
class.
7. GLOBAL CLASS AND LOCAL CLASS
Global Class: Global classes and interfaces are
defined in the Class Builder (Transaction SE24) in
the ABAP Workbench. All of the ABAP programs in
an R/3 System can access the global classes.
Local Class: Local classes are define in an ABAP
program (Transaction SE38) and can only be used
in the program in which they are defined.
8. OBJECT
Objects are nothing but instances of classes, each
object has a unique identity that is memory and it`s
own attributes.
SYNTAX
DATA <instance> TYPE REF TO <class name> .
CREATE OBJECT <instance> .
9. INHERITANCE
When one object acquires all the properties and
behaviours of parent object i.e. known as
inheritance. It provides code reusability.
Inheritance is the concept of passing the behavior
of one class to another class.
SUPER is the keyword used to represent the super
class in oops, you can access the methods and
attributes the super class using this word super.
REDIFINATION is the keyword which is used to
overwrite the parent class methods with new
definition.
10. POLYMORPHISM
It is a concept by which the same method names
will behave differently in different classes i.e each
method will have its own implementation in different
different classes but with the same name.
Interface is one of the concept in Object Oriented
ABAP to achieve Polymorphism.
11. ABSTRACTION
Hiding internal details and showing
functionality is known as abstraction. For
example: phone call, we don't know the internal
processing.
In SAP, we use abstract class and interface to
achieve abstraction.
12. ENCAPSULATION
Binding (or wrapping) code and data together
into a single unit is known as encapsulation .
Wrapping up of data into single unit. Or, restriction
on visibility of attributes and methods in the class.
We have 3 levels of visibility:
1. Private
2. Protected
3. Public