Anda di halaman 1dari 8

OO ABAP Elements

CLASSES, ATTRIBUTES & METHODS


Classes, Attributes & Methods

The concept of classes is the foundation for all object-oriented


thinking.
A class is a set of objects that have the same structure and the same
behavior.

We will start with a simple demonstration, lets create a class


for our previous function group example, we will call it
ZCL_VEHICLE.
Our class will have the following components:
ZCL_VEHICLE: Class Components

Private Public
Component Component
s s

Speed Increase_speed
Private Access, Public Access,
generally: generally:
Attributes Methods
Data Types Attributes can be Decrease_speed Events
one of three types:
Elementary
Structured
Table Type Get_speed
TO CREATE AN ABAP
Practical CLASS, OPEN
TRANSACTION CODE
Example SE24.
Attributes: Visibility & Level

Visibility Level
Public Attributes: Instance Attributes:
Generally Visible Exist per instance
Generally changeable. Exception: Defined with DATA
READ-ONLY addition.

Static Attributes:
Private Attributes
Exist per class
Only visible within the class
Definition with CLASS-DATA
Only changeable within the class

Lets go back to SE24 and create more


attributes
Methods: Visibility & Level

Visibility Level
Public Methods: Instance Methods:
Can generally be called Access to static and instance
components is possible
Defined with METHODS
Private Methods:
Can only be called within the class
Static Methods:
Only access to static components is
possible
Defined with CLASS-METHODS
You can access public
attributes and methods
Access to Static from outside a class (e.g.

and Instance from a main program)

Elements Static attributes are


accessed using:
classname=>static_attri
ATTRIBUTES AND METHODS bute.

Instance attributes are


accessed with :
ref->instance_attribute.
Practical LETS CREATE A PROGRAM
THAT USES CLASS:
Example ZCL_VEHICLE

Anda mungkin juga menyukai