oo abap 23 march 2012shri

Post on 30-Oct-2014

51 Views

Category:

Documents

15 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Thanks,

Object Oriented Programming with ABAP

Compare car parts with assembled car ;

which is better to understand ?

ByShrinivas

Kendre

Thanks,

Abstraction and Encapsulation

Thanks,

• Classes• Objects/ Instances• Constructors• Inheritance• Polymorphism• Interface• Abstract Class• Final Class• Events

OOP’s Concepts !

It’s a template or blue-print of a Object which contains attributes, methods and events.

Class

Syntax

Thanks, If car is a Class ,then SUV, Hatch back, Sedan, Convertible are objects • Instance of a class

• It’s a variable of a type class

• Objects can be created and addressed using reference variables.

Object

Syntax

Thanks,

Attributes

• Attributes describe the data that can be stored in the objects in a class.

• Types– Instance attributes– Class attributes

• Visibility– Private– Public

Thanks, Attributes and visibility

Thanks, Attributes and visibility

Thanks,

Attributes

• Attributes describe the data that can be stored in the objects in a class.

• Types– Instance attributes– Class attributes

• Visibility– Private– Public

Thanks,

• Methods are internal procedures in classes that determine the behavior of an object

• Methods have a parameter interface• Types

– Instance method– Class method

• Visibility– Private– Public

Methods

Thanks,Methods -visibility

Calling Methods :Syntax

Thanks,Methods –Instance/class

Thanks,Calling a Method

Calling Methods :Syntax

Thanks,Calling a Method

Thanks,

Constructor

Thanks,Static Constructor

• Named as CLASS_CONSTRUCTOR• Called automatically before the class is first accessed.

– Before any of the following actions• CREATE OBJECT• Addressing static attribute cl_sample=>name.• Addressing static method CALL METHOD cl_sample=>set_name• Before registering static event handler using SET HANDLER

– <class name>=><handler method> FOR obj

Thanks,

Inheritance

• Inheritance is a relationship in which one class (the subclass) inherits all the main characteristics of another class (the superclass).

• The subclass can also add new components (attributes, methods, and so on) and replace inherited methods with its own implementations.

• The inheritance relationship is often described as an “is-a” relationship: a passenger plan is an airplane.

Thanks,Inheritance –

Visibility

• The constructor of the super class must be called within the constructor of the subclass.

• For static constructors, unlike instance constructors, the static constructor in the super class is called automatically.

Thanks,

Polymorphism

• Ability to take multiple forms• Same method name with different functionality• Achieved using the keyword REDEFINITION• Same method name is not allowed use in the sub classes.

Thanks,

Polymorphism –Tips

• The REDEFINITION statement for the inherited method must be in the same SECTION as the definition of the original method.

• (It can therefore not be in the PRIVATE SECTION, since a class’s private methods are not visible and therefore not redefinable in subclasses!)

• If you redefine a method, you do not need to enter its interface again in the subclass, but only the name of the method. The reason for this is that ABAP Objects does not support overlaying (see notes to previous slide).

Thanks,

Interface

• Basis for polymorphism• Achieve Multiple Inheritance• Independent structures that allow you to enhance the class• The class which implements this interface will provide a

implementation to this method

Thanks,

Abstract Class

• Cannot be instantiated• Used in incomplete blueprint • The subclass needs to redefine the undefined methods• Can have abstract or instance methods• Classes with at least one abstract method are themselves abstract• Static methods and constructors cannot be abstract (they cannot be

redefined).

Thanks,

Final Class

• A final class cannot have subclasses, and can protect itself in this way against (uncontrolled) specialization.

• A final method in a class cannot be redefined in a subclass, and can protect itself in this way against (uncontrolled) redefinition.

• Some characteristics:• A final class implicitly only contains final methods. You cannot enter

FINAL explicitly for these methods in this case.• Methods cannot be both final and abstract.• Classes, on the other hand, can usefully be both abstract and final:

only static components can be used there.

Thanks,

Events

Event Registration

Triggering an event

Handling event

Thanks,Global Class vs Local Class

Local

Glo

bal

Global Class – Class Builder

Class Edior– Step by Step Demo

SE24 - Class Builder

Class Edior– Most important thing in programmer’s life

• Copy /Convert Local Class to Global Class• Copy Super class to Sub class• Copy class methods/attributes among associated class• Demo :

SE24 -Demo -Refactoring

Show me The Code !!!!

Program Name Concept Source Code

ZKENDRE_OOABAP_ATTRIBUTE Class Attribute

ZKENDRE_OOABAP_METHOD Class Method

ZKENDRE_OOABAP_CONSTRUCTOR Class Constructor and Constructor

ZKENDRE_OOABAP_INHERITANCE Inheritance

ZKENDRE_OOABAP_POLYMORPHISM Polymorphism

ZKENDRE_OOABAP_INTERFACE Interface

Class Attribute Demo Program

Class Method Demo

Constructor DemoUML Diagram

Inheritance

Polymorphism

Interface

Show me The Code !!!!

Program Name Concept Source Code

ZKENDRE_OOABAP_FINAL Final Class

ZKENDRE_OOABAP_ABSTRACT Abstract Class

ZKENDRE_OOABAP_EVENT Event Concept

ZKENDRE_OOABAP_EVENT_EDITALVEditable ALV using OO ABAP events

ZKENDRE_OOABAP_GLOBAL_CLASS Global class

ZKENDRE_OOABAP_LOCAL_T_GLOB Convert local class to Global

Final

Abstract

Event

Advance Event - Editable ALV

Call Global class in Program

Convert local to global

Let’s have some hand’s on on system

There is lot to dig!!!!

• Binding : http://www.saptechnical.com/Tutorials/OOPS/Binding/Procedure.htm • Casting :• Garbage collector• Friend class…………………etc !!!

Thanks,

Oops …………. The End

top related