Top Banner
Hyderabad February 24-26th 2009 Instructor: Subhas Katikala. Object Oriented ABAP
69
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: OOPS-ABAP

Hyderabad February 24-26th 2009

Instructor: Subhas Katikala.

Object Oriented ABAP

Page 2: OOPS-ABAP

Workshop Goals

This workshop will enable you to:

• Learn object – oriented concepts.

• Learn the principle of object - oriented programming.

• Learn the application of object

- oriented ABAP.

Page 3: OOPS-ABAP

Course Contents

Object Oriented ConceptsObject Oriented Programming.Advantages of the Object-Oriented Approach

Methods• Syntax and Visibility• Instance Methods and Static Methods• Constructor

Reference Variables• Creating References• Assigning References

ClassesComponents of a Class

Attributes• Syntax and Visibility• Instance Attributes and Static Attributes

Page 4: OOPS-ABAP

Course Contents

Inheritance Super classes and Subclasses Visibility Inheritance and the (Instance) Constructor Parameters Redefining Methods in OOABAP Compatibility Principles of the Narrowing Cast Static and Dynamic Components Final Classes and Methods

Page 5: OOPS-ABAP

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 Compound Interfaces

Page 6: OOPS-ABAP

Course Contents

Events Define and Trigger Events Handle Events Register and deregister Events Receive a reference from Sender

Page 7: OOPS-ABAP

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 worldModel

DataMethodMethodMethod

DataMethodMethodMethod

DataMethodMethodMethod

Boat

DataMethodMethodMethod

Page 8: OOPS-ABAP

Object Oriented Programming

• Encapsulation

• Inheritance

• Polymorphism

• Instantiation

• Interfacing

• Events

OOPS

Page 9: OOPS-ABAP

Advantages

• Simplicity

• Explicitness

• Maintainability

• Future Orientation

Page 10: OOPS-ABAP

• 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.

Classes

Page 11: OOPS-ABAP

• 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.

Classes

Page 12: OOPS-ABAP

Components in a class

Page 13: OOPS-ABAP

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. 

Classes

Page 14: OOPS-ABAP

Attributes

Page 15: OOPS-ABAP

Defining Local Classes

Classes

Page 16: OOPS-ABAP

Attributes, Types, Constants - Syntax

Page 17: OOPS-ABAP

Attributes and Visibility

Page 18: OOPS-ABAP

Instance attributes and Static attributes

Page 19: OOPS-ABAP

Methods

Page 20: OOPS-ABAP

Methods : Syntax

Page 21: OOPS-ABAP

Methods and Visibility

Page 22: OOPS-ABAP

Instance methods and Static methods

Page 23: OOPS-ABAP

Instance methods and Static methods : Example

Page 24: OOPS-ABAP

Constructor

Page 25: OOPS-ABAP

Constructor : Example

Page 26: OOPS-ABAP

Static Constructor : Implementation

Page 27: OOPS-ABAP

Static Constructor : Call Examples

Page 28: OOPS-ABAP

Creating Objects

Page 29: OOPS-ABAP

Reference Variables

Page 30: OOPS-ABAP

Creating Objects : Syntax

Page 31: OOPS-ABAP

Assigning References

Page 32: OOPS-ABAP

• 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.

Inheritance

Page 33: OOPS-ABAP

Inheritance

Page 34: OOPS-ABAP

Inheritance : Syntax

Page 35: OOPS-ABAP

Relationships between super classes and subclasses

Relationships between super classes and subclasses

Page 36: OOPS-ABAP

Inheritance and Visibility

Page 37: OOPS-ABAP

Inheritance and (Instance) constructor

Page 38: OOPS-ABAP

Parameters and CREATE OBJECT

Page 39: OOPS-ABAP

Redefining Methods in ABAP Objects

Page 40: OOPS-ABAP

Redefining Methods : Example

Page 41: OOPS-ABAP

Compatibility and Narrowing Cast

Page 42: OOPS-ABAP

Principles of the Narrowing Cast

Page 43: OOPS-ABAP

Static and Dynamic Types: Example

Page 44: OOPS-ABAP

Static and Dynamic Types for References

Page 45: OOPS-ABAP

Widening the Cast

Static and Dynamic Types for References

Page 46: OOPS-ABAP

Widening the cast

Page 47: OOPS-ABAP

Polymorphism

Page 48: OOPS-ABAP

Polymorphism

Page 49: OOPS-ABAP

Polymorphism

Page 50: OOPS-ABAP

• Interfaces exclusively describe the external point of contact of a class, but they do not contain their own implementation part.

Interface

Page 51: OOPS-ABAP

Defining and Implementing Interface

Page 52: OOPS-ABAP

Working with Interface components

Page 53: OOPS-ABAP

Interface References Narrowing casting

Page 54: OOPS-ABAP

• 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.

Interface

Page 55: OOPS-ABAP

Interface references widening cast

Page 56: OOPS-ABAP

• 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.

Interface

Page 57: OOPS-ABAP

• 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>~”.

Using several Interface

Page 58: OOPS-ABAP

Polymorphism and Interface

Page 59: OOPS-ABAP

• Objects or Classes use events to trigger Event Handler methods in other objects or classes.

• When an event is triggered any number of Event Handler Methods can be called.

• The events of a class can be raised in the same class using the RAISE EVENT Statement.

• Events have only output parameters which are accepted by the Event Handler Methods as input parameters.

• The link between the trigger and the handler is established dynamically at runtime using the statement SET HANDLER.

Events

Page 60: OOPS-ABAP

Events Overview

Page 61: OOPS-ABAP

Triggering and handling Events : Overview

Page 62: OOPS-ABAP

Defining and Triggering Events

Page 63: OOPS-ABAP

Handling and Registering Events

Page 64: OOPS-ABAP

Handling Events

Page 65: OOPS-ABAP

Registering for an Event : Syntax

Page 66: OOPS-ABAP

Deregistration

Page 67: OOPS-ABAP

Registration/Deregistration : Handler Table

Page 68: OOPS-ABAP

Event handling : Characteristics

Page 69: OOPS-ABAP

Events and Visibility