Hyderabad February 24-26th 2009
Hyderabad February 24-26th 2009
Instructor: Subhas Katikala.
Instructor: Subhas Katikala.
Object Oriented ABAP
Workshop Goals
Workshop Goals
Th
Th
is works
is works
hhop will enable you to:
op will enable you to:
LLearn earn objeobject ±ct ± orieoriented cnted conceoncepts.pts.
LLearn tearn thhe prie principnciple of ole of objecbject -t - orienorientedted
programming. programming.
LLearn tearn thhe application of objecte application of object
Workshop Goals
Workshop Goals
Th
Th
is works
is works
hhop will enable you to:
op will enable you to:
LLearn earn objeobject ±ct ± orieoriented cnted conceoncepts.pts.
LLearn tearn thhe prie principnciple of ole of objecbject -t - orienorientedted
programming. programming.
LLearn tearn thhe application of objecte application of object
C
Course
ourse C
Contents
ontents
O
Objectbject OOriented Conceptsriented Concepts O
Objectbject OOriented Programming.riented Programming.
Advantages of the
Advantages of the OObject-bject-OOriented Approachriented Approach
M
Metethhodsods
Syntax and VisibilitySyntax and Visibility
Instance Methods and Static MethodsInstance Methods and Static Methods Constructor Constructor
Reference
Reference VariVariablesables
Creating ReferencesCreating References Assigning References Assigning References
Classes Classes Components of a Class Components of a Class Attributes Attributes
Syntax and VisibilitySyntax and Visibility
Course Contents
Inheritance
Super classes and Subclasses
Visibility
Inheritance and the (Instance) Constructor
Parameters
Redefining Methods in OO ABAP
Compatibility
Principles of the Narrowing Cast
Static and Dynamic Components
Course Contents
Polymorphism
Advantages Compared to Procedural Programming
Abstract Classes and Methods
Component Namespaces in Classes
Interfaces
Defining and Implementing an Interface
Working with Interface Components
Interface References
Narrowing Cast
Widening Cast
Using Several Interfaces
Polymorphism and Interfaces
Polymorphism and Inheritance
Course Contents
Events
Define and Trigger Events
Handle Events
Register and deregister Events
Object ² Oriented Concepts
What are Objects ?
¥ SAP AG 1999 What Are Objects? Tree House Crane Objects are an abstraction of the real world
Objects are units made up of data and of the functions belonging to that data
Real world Model Data MMetethhodod Method Data MMetethhodod Method Data MMetethhodod Method Boat Data MMetethhodod Method
Object Oriented Programming
Encapsulation Inheritance Polymorphism Instantiation Interfacing EventsOOPS
Ad
vantages
Simplicity Explicitness Maintainability
Classes are the central element of object-orientation.
A Class is an abstract description of an object.
Classes are templates for objects.
The attributes of objects are defined by the components of
the class, which describe the state and behavior of objects.
You define global classes and interfaces in the Class
Builder (Transaction SE24) in the ABAP Workbench.
They are stored centrally in class pools in the class library
in the R/3 Repository.
All of the ABAP programs in an R/3 System can access the
global classes.
Defining
Local Classes
A complete class definition consists of a declaration part and, if required, an
implementation part.
The declaration part of a class <class> is a statement block: CLASS c1 DEFINITION.
«.
ENDCLASS.
If you declare methods in the declaration part of a class, you must also write an
implementation part for it.
CLASS c1 IMPLEMENTATION.
«.
ENDCLASS.
Defining
Local Classes
Inheritance allows you to derive a new class from an existing class. You do this using the INHERITING FROM addition in the
CLASS <subclass> DEFINITION INHERITING FROM <superclass>
statement.
The new class <subclass> inherits all of the components of the existing
class <superclass>.
The new class is called the subclass of the class from which it is
derived.
The original class is called the superclass of the new class.
Relationships between super classes and subclasses
Relationships between super classes and
W
idening t
he Cast
Interfaces exclusively describe the external point
of contact of a class, but they do not contain their
own implementation part.
The assignment of an object reference to an interface
reference is known as a narrowing cast since, as with
inheritance, only a part of the object interface is visible once you have assigned the reference.
With an interface reference, you can no longer address all
components in the class carrying out the implementation, but only the components defined in the interface.
The widening cast is, as with inheritance, the opposite of the
narrowing cast: here it is used to retrieve an object reference from an interface reference. Obviously it cannot be statically
checked, since an interface can be implemented by more than one class.
An object reference cannot be assigned to an interface
reference if it has itself not implemented the corresponding interface.
In the above example, one class is implementing several
interfaces.Even if these interfaces contain components with the
same name, they are differentiated in the class carrying out the
implementation by the prefix ³<interfacename>~´.
P
OObjects or Classes use events to bjects or Classes use events to trigger Event Handler methods intrigger Event Handler methods in
other objects or classes.
other objects or classes.
When an event is triggered any When an event is triggered any number of Event Handler Methods cannumber of Event Handler Methods can
be called.
be called.
The events of a class can be raised in the The events of a class can be raised in the same class using thesame class using the RAISERAISE EVENT
EVENT Statement.Statement.
Events have only output parameters which are accepted by Events have only output parameters which are accepted by the Eventthe Event
Handler Methods as input parameters.
Handler Methods as input parameters.
The link between the trigger and the handler is established dynamicallyThe link between the trigger and the handler is established dynamically
at runtime using the statement
at runtime using the statement SET HANDLERSET HANDLER..
Events
Events
Events
Triggering and handling Events : Overview
Registration/Deregistration : Handler