SlideShare a Scribd company logo
1 of 34
Object Oriented ConceptsObject Oriented Concepts
&&
ABAP ObjectsABAP Objects
ByBy
Dharmesh KumarDharmesh Kumar
ObjectivesObjectives
• Understand basic concepts of Object Oriented
Programming
• Components of a Class
• Identify the characteristics of OOP
• Implement the characteristics of OOP in ABAP Objects
Basic concept of Object Oriented ProgrammingBasic concept of Object Oriented Programming
The fundamental idea behind Object Oriented Programming
(OOP) is to combine both data and the functions or
methods (which operates on that data) into a single unit.
Such units, in general terminology, are called Object.
OBJECT
VEHICLE
Plate No
Speed
Accelerate( )
Show_Speed( )
UNIT
Need of Object Oriented ProgrammingNeed of Object Oriented Programming
Higher level of abstraction for solving real-life problems
Reusability
Allows to think in the problem space rather than thinking about
data declaration, decisions, loops etc. like in procedural
languages.
Better control over process visibility
Components of a ClassComponents of a Class
There are three components
• AttributesAttributes
• MethodsMethods
• EventsEvents
CLASS vehicle
DATA : speed TYPE i.
METHODS : accelerate,
show_speed.
EVENTS : seatBeltSign
Creating class instanceCreating class instance
Creating a class instance is somewhat similar to creating a data object by
taking reference of a data type.
DATA : my_var TYPE i.
For creating class instance :
1) Data : obj_vehicle TYPE REF TO vehicle.
a reference variable of type “pointer to an object of the vehicle class” is created
2) CREATE OBJECT obj_vehicle.
an instance of the vehicle class is created
a reference to this instance is assigned to “obj_vehicle”
Type of componentsType of components
• Static Component
• Instance Component
Instance components exist separately in each instance (object)
of the class.
•DATA
•METHODS (Can access all attributes and events of their own class)
•EVENTS
Static components only exist one per class and are valid for all
instances of the class.
•CLASS-DATA
•CLASS-METHODS (Can access only static attributes and static events )
•CLASS-EVENTS
•CONSTANTS
See Program YCLASS_STATIC (TRZ300)
Type of components Contd..Type of components Contd..
Instance Attribute
Static Attribute
Definition
Implementation
Instantiation
Output
CLASS (Global + Local)CLASS (Global + Local)
Classes can be of two types
• Global class
• Local class
Global vs Local Global Local
Accessibility Any program Only within the
program where it is
defined
Stored in Class repository In the program where it
is defined
Tools to create SE24 Class builder SE38 ABAP Editor
Namespace Must begin with ‘Y’ or
‘Z’
Any
Class declaration (Local)Class declaration (Local)
CLASS vehicle DEFINITION.
DATA speed TYPE I VALUE 0.
METHODS: accelerate,
show_speed.
ENDCLASS.
CLASS vehicle IMPLEMENTATION.
METHOD accelerate.
speed = speed + 1.
ENDMETHOD.
METHOD show_speed.
WRITE speed.
ENDMETHOD.
ENDCLASS.
DEFINITION IMPLEMENTATION
• The purpose of abstract class is to act as a ‘Model’ for subclasses.
• They cannot be instantiated.
• To use an abstract class, it has to be inherited in the subclass and its
abstract method should redefined.
• Abstract methods does not need to implemented in super class
Why use abstract class ?
An abstract class is used when we want to model an object, the final
state of which is not known at the time of modeling and will be known
later
Abstract ClassAbstract Class
Abstract Class Contd..Abstract Class Contd..
If a method is declared as abstract, then
there is not need to implement it in super
class but it needs to be ‘redefined’ in
subclass.
• A class that is defined as final class can not be inherited further.
• All Methods of a final class are inherently final and must not be
declared as final in the class definition.
• Also, a final method can not be redefined further.
• If only a method of a class is final then that class can be inherited but
that method cannot be redefined.
Why use final class ?
If you don't want anyone else to change or override the functionality
of your class then you can define it as final. Thus no one can inherit
and modify the features of this class.
Final ClassFinal Class
Final Class Contd..Final Class Contd..
Final Class
Final Method
Final Subclass method
Class VariantsClass Variants
CLASS class DEFINITION DEFERRED.
When the class needs to be referred before it is being defined.
As we have deferred it at the initial stage, the system would not look for this class at higher
level context, such as global class library.
Class Variants Cont..Class Variants Cont..
CLASS <class> DEFINITION LOAD.
•The definition of global classes loads into the memory when a local class is used first time in a
program.
•When the first access is to a ‘static component’ or in the ‘definition of an event handler
method’ then the global class needs to be loaded explicitly into the memory first.
CLASS CL_GUI_PICTURE DEFINITION LOAD.
CLASS C1 DEFINITION. PUBLIC SECTION.
METHODS HANDLER FOR EVENT PICTURE_CLICK OF CL_GUI_PICTURE.
ENDCLASS.
CLASS C1 IMPLEMENTATION.
METHOD HANDLER.
...
ENDMETHOD.
ENDCLASS.
Characteristics of Object OrientedCharacteristics of Object Oriented
languagelanguage
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism
AbstractionAbstraction
“Abstraction is the elimination of the irrelevant and amplification of the essentials”
Everything that is important to the user is visible, but everything that is not, is hidden.
Essentials
Accelerator
Brake
Steering wheel
Irrelevant
Engine mechanism
Gear mechanism
Brake mechanism
Visibility All
users
Subclass
methods
Class
methods
PUBLIC X X X
PROTECTED X X
PRIVATE X
EncapsulationEncapsulation
ALL
USERS
CLASS C1
PUBLIC PRIVATE
SUBCLASSES of C1
PROTECTED
METHODS
Encapsulation is Hiding data!
Encapsulation is hiding process; hence
then you hide the data. Not vice versa
Encapsulation Contd..Encapsulation Contd..
See Program YCLASS_ENCAP_DEMO (TRZ300)
DEFINITION IMPLEMENTATION
InheritanceInheritance
Inheritance is the process of creating new classes, called derived classes or
subclasses or child classes from existing classes called base classes or super
classes or parent classes. The derived class inherits all the capabilities of the
base class but can add refinements of its own.
The base class is unchanged by this process.
VEHICLEVEHICLE
accelerate()
show_speed()
PLANEPLANE
accelerate()
show_speed()
rise()
TORPEDOTORPEDO
accelerate()
show_speed()
sink()
FIGHTER JETFIGHTER JET
accelerate()
show_speed()
rise()
launch_missile()
Inheritance Contd..Inheritance Contd..
Syntax for creating sub classes (local):
See Program YCLASS_INHERT_DEMO (TRZ300)
For global classes, go to transaction SE24 -> properties tab and define
the super class.
PolymorphismPolymorphism
Polymorphism is a characteristic of being able to assign a different behavior or
value in a subclass, to something that was declared in a parent class.
VEHICLEVEHICLE
accelerate()
show_speed()
PLANEPLANE
accelerate()
show_speed() Redefinition
TORPEDOTORPEDO
accelerate()
show_speed() Redefinition
Polymorphism Contd..Polymorphism Contd..
See Program YCLASS_POLY_DEMO (TRZ300)
(Using inheritance)
Method Redefinition
ConstructorConstructor
A constructor is a special method which is
automatically executed by the runtime
environment.
They are used to set an object dynamically to a
defined initial state.
There are two type of constructor
1. Instance Constructor
They are called once for each instance after the complete creation of the instance with the
CREATE OBJECT statement.
2. Static Constructor
They are called in a program once for each class before the class is accessed for the first
time.
Call components (static + instance)Call components (static + instance)
• Attributes
Call instance attribute of an object
Static attribute of an object
oref->attr
Static attribute of a class class=>attr
Its own instance attribute
Its own static attribute
me->attr OR
attr
• Methods
Call instance method of an object
Static method of an object
CALL METHOD oref->meth
Static method of a class CALL METHOD class=>meth
Its own instance method
Its own static method
CALL METHOD me->meth OR
CALL METHOD meth
Interfaces
• Interfaces extends scope of a class by adding
there own components to the class.
• Interfaces can only be defined in ‘PUBLIC
SECTION’ of class definition.
• Interfaces do not have an implementation part
or instance.
• Interfaces can be implemented by different
classes and its methods can be implemented
differently in each class.
• Interface components can be called directly
after assigning class reference to interface
reference. (<iref> = <cref> )
Type of InterfacesType of Interfaces
• Local Interface
• Global Interface
Local Interface
Interface <intf>
Method meth1
Endinterface
Class <class> definition
PUBLIC SECTION
Interfaces <intf>
METHODS : meth1
Endclass
Class <class> implementation
method <intf>~meth1
endmethod
method meth1
endmethod
Endclass
1. Define Interface
2. Declare in class
3. Implement Interface methods
Local Interface Alias
Aliases are short names given to methods of interfaces for easy access.
Interface <interface>
Method method
Endinterface
Class <class> definition
Interfaces <interface>.
Aliases : m1 FOR <interface>~method
Endclass
CALL METHOD <class>->interface~method.
CALL METHOD <class>->m1.


Interface Contd..
Both local and global interfaces can be accessedBoth local and global interfaces can be accessed
using the following waysusing the following ways
Class reference variable
CALL METHOD <cl>CALL METHOD <cl>->-><intf>~<meth><intf>~<meth>
• Using alias :
CALL METHOD <cl>CALL METHOD <cl>->-><meth><meth>
Interface reference variable
<intf>= <cref> (class reference)
CALL METHOD <intf>CALL METHOD <intf>->-><meth><meth>
Interface Contd..
• For static components only CONSTANT can be accessed
using interface name <intf>=><const>
• Other STATIC COMPONENTS cannot be accessed using
interface name but only through class.
Access static attribute
<class>=><intf~attr>
Access static method
CALL METHOD <class>=><intf~meth>
EventsEvents
THANK YOU.

More Related Content

What's hot

abap list viewer (alv)
abap list viewer (alv)abap list viewer (alv)
abap list viewer (alv)Kranthi Kumar
 
Core Data Service
Core Data ServiceCore Data Service
Core Data ServiceSujoy Saha
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialscesarmendez78
 
Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answersUttam Agrawal
 
Bdc BATCH DATA COMMUNICATION
Bdc BATCH DATA COMMUNICATIONBdc BATCH DATA COMMUNICATION
Bdc BATCH DATA COMMUNICATIONHitesh Gulani
 
Introducing enhancement framework.doc
Introducing enhancement framework.docIntroducing enhancement framework.doc
Introducing enhancement framework.docKranthi Kumar
 
Sap abap ale idoc
Sap abap ale idocSap abap ale idoc
Sap abap ale idocBunty Jain
 
Call transaction method
Call transaction methodCall transaction method
Call transaction methodKranthi Kumar
 
1000 solved questions
1000 solved questions1000 solved questions
1000 solved questionsKranthi Kumar
 
0104 abap dictionary
0104 abap dictionary0104 abap dictionary
0104 abap dictionaryvkyecc1
 

What's hot (20)

SAP ALE Idoc
SAP ALE IdocSAP ALE Idoc
SAP ALE Idoc
 
abap list viewer (alv)
abap list viewer (alv)abap list viewer (alv)
abap list viewer (alv)
 
Core Data Service
Core Data ServiceCore Data Service
Core Data Service
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
Sap abap
Sap abapSap abap
Sap abap
 
CDS Views.pptx
CDS Views.pptxCDS Views.pptx
CDS Views.pptx
 
Abap Objects for BW
Abap Objects for BWAbap Objects for BW
Abap Objects for BW
 
Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answers
 
SAP Smart forms
SAP Smart formsSAP Smart forms
SAP Smart forms
 
Bdc BATCH DATA COMMUNICATION
Bdc BATCH DATA COMMUNICATIONBdc BATCH DATA COMMUNICATION
Bdc BATCH DATA COMMUNICATION
 
Introducing enhancement framework.doc
Introducing enhancement framework.docIntroducing enhancement framework.doc
Introducing enhancement framework.doc
 
Badis
Badis Badis
Badis
 
SAP ABAP data dictionary
SAP ABAP data dictionarySAP ABAP data dictionary
SAP ABAP data dictionary
 
Reports
ReportsReports
Reports
 
Sap abap ale idoc
Sap abap ale idocSap abap ale idoc
Sap abap ale idoc
 
Abap reports
Abap reportsAbap reports
Abap reports
 
Call transaction method
Call transaction methodCall transaction method
Call transaction method
 
1000 solved questions
1000 solved questions1000 solved questions
1000 solved questions
 
0104 abap dictionary
0104 abap dictionary0104 abap dictionary
0104 abap dictionary
 
Sap abap
Sap abapSap abap
Sap abap
 

Similar to OOP Concepts and ABAP Objects

Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basicsvamshimahi
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1bharath yelugula
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHPVibrant Technologies & Computers
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingNithyaN19
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2Rakesh Madugula
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++VishnuSupa
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptxRaazIndia
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxKunalYadav65140
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)Khaled Anaqwa
 
CHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptx
CHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptxCHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptx
CHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptxarbazkhan950274
 
Abap Inicio
Abap InicioAbap Inicio
Abap Iniciounifor
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingAllan Mangune
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for seleniumapoorvams
 
Oop(object oriented programming)
Oop(object oriented programming)Oop(object oriented programming)
Oop(object oriented programming)geetika goyal
 

Similar to OOP Concepts and ABAP Objects (20)

Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Lab 4 (1).pdf
Lab 4 (1).pdfLab 4 (1).pdf
Lab 4 (1).pdf
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
CHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptx
CHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptxCHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptx
CHAPTER 1 BLUE JAVE ITRODUCTION TO OBJECT ORIENTED PROGRAMMING L2.pptx
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Oops
OopsOops
Oops
 
Abap Inicio
Abap InicioAbap Inicio
Abap Inicio
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & Programming
 
Inheritance
InheritanceInheritance
Inheritance
 
VB.net&OOP.pptx
VB.net&OOP.pptxVB.net&OOP.pptx
VB.net&OOP.pptx
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
Oop(object oriented programming)
Oop(object oriented programming)Oop(object oriented programming)
Oop(object oriented programming)
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 

Recently uploaded

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

OOP Concepts and ABAP Objects

  • 1. Object Oriented ConceptsObject Oriented Concepts && ABAP ObjectsABAP Objects ByBy Dharmesh KumarDharmesh Kumar
  • 2. ObjectivesObjectives • Understand basic concepts of Object Oriented Programming • Components of a Class • Identify the characteristics of OOP • Implement the characteristics of OOP in ABAP Objects
  • 3. Basic concept of Object Oriented ProgrammingBasic concept of Object Oriented Programming The fundamental idea behind Object Oriented Programming (OOP) is to combine both data and the functions or methods (which operates on that data) into a single unit. Such units, in general terminology, are called Object. OBJECT VEHICLE Plate No Speed Accelerate( ) Show_Speed( ) UNIT
  • 4. Need of Object Oriented ProgrammingNeed of Object Oriented Programming Higher level of abstraction for solving real-life problems Reusability Allows to think in the problem space rather than thinking about data declaration, decisions, loops etc. like in procedural languages. Better control over process visibility
  • 5. Components of a ClassComponents of a Class There are three components • AttributesAttributes • MethodsMethods • EventsEvents CLASS vehicle DATA : speed TYPE i. METHODS : accelerate, show_speed. EVENTS : seatBeltSign
  • 6. Creating class instanceCreating class instance Creating a class instance is somewhat similar to creating a data object by taking reference of a data type. DATA : my_var TYPE i. For creating class instance : 1) Data : obj_vehicle TYPE REF TO vehicle. a reference variable of type “pointer to an object of the vehicle class” is created 2) CREATE OBJECT obj_vehicle. an instance of the vehicle class is created a reference to this instance is assigned to “obj_vehicle”
  • 7. Type of componentsType of components • Static Component • Instance Component Instance components exist separately in each instance (object) of the class. •DATA •METHODS (Can access all attributes and events of their own class) •EVENTS Static components only exist one per class and are valid for all instances of the class. •CLASS-DATA •CLASS-METHODS (Can access only static attributes and static events ) •CLASS-EVENTS •CONSTANTS See Program YCLASS_STATIC (TRZ300)
  • 8. Type of components Contd..Type of components Contd.. Instance Attribute Static Attribute Definition Implementation Instantiation Output
  • 9. CLASS (Global + Local)CLASS (Global + Local) Classes can be of two types • Global class • Local class Global vs Local Global Local Accessibility Any program Only within the program where it is defined Stored in Class repository In the program where it is defined Tools to create SE24 Class builder SE38 ABAP Editor Namespace Must begin with ‘Y’ or ‘Z’ Any
  • 10. Class declaration (Local)Class declaration (Local) CLASS vehicle DEFINITION. DATA speed TYPE I VALUE 0. METHODS: accelerate, show_speed. ENDCLASS. CLASS vehicle IMPLEMENTATION. METHOD accelerate. speed = speed + 1. ENDMETHOD. METHOD show_speed. WRITE speed. ENDMETHOD. ENDCLASS. DEFINITION IMPLEMENTATION
  • 11. • The purpose of abstract class is to act as a ‘Model’ for subclasses. • They cannot be instantiated. • To use an abstract class, it has to be inherited in the subclass and its abstract method should redefined. • Abstract methods does not need to implemented in super class Why use abstract class ? An abstract class is used when we want to model an object, the final state of which is not known at the time of modeling and will be known later Abstract ClassAbstract Class
  • 12. Abstract Class Contd..Abstract Class Contd.. If a method is declared as abstract, then there is not need to implement it in super class but it needs to be ‘redefined’ in subclass.
  • 13. • A class that is defined as final class can not be inherited further. • All Methods of a final class are inherently final and must not be declared as final in the class definition. • Also, a final method can not be redefined further. • If only a method of a class is final then that class can be inherited but that method cannot be redefined. Why use final class ? If you don't want anyone else to change or override the functionality of your class then you can define it as final. Thus no one can inherit and modify the features of this class. Final ClassFinal Class
  • 14. Final Class Contd..Final Class Contd.. Final Class Final Method Final Subclass method
  • 15. Class VariantsClass Variants CLASS class DEFINITION DEFERRED. When the class needs to be referred before it is being defined. As we have deferred it at the initial stage, the system would not look for this class at higher level context, such as global class library.
  • 16. Class Variants Cont..Class Variants Cont.. CLASS <class> DEFINITION LOAD. •The definition of global classes loads into the memory when a local class is used first time in a program. •When the first access is to a ‘static component’ or in the ‘definition of an event handler method’ then the global class needs to be loaded explicitly into the memory first. CLASS CL_GUI_PICTURE DEFINITION LOAD. CLASS C1 DEFINITION. PUBLIC SECTION. METHODS HANDLER FOR EVENT PICTURE_CLICK OF CL_GUI_PICTURE. ENDCLASS. CLASS C1 IMPLEMENTATION. METHOD HANDLER. ... ENDMETHOD. ENDCLASS.
  • 17. Characteristics of Object OrientedCharacteristics of Object Oriented languagelanguage 1. Abstraction 2. Encapsulation 3. Inheritance 4. Polymorphism
  • 18. AbstractionAbstraction “Abstraction is the elimination of the irrelevant and amplification of the essentials” Everything that is important to the user is visible, but everything that is not, is hidden. Essentials Accelerator Brake Steering wheel Irrelevant Engine mechanism Gear mechanism Brake mechanism
  • 19. Visibility All users Subclass methods Class methods PUBLIC X X X PROTECTED X X PRIVATE X EncapsulationEncapsulation ALL USERS CLASS C1 PUBLIC PRIVATE SUBCLASSES of C1 PROTECTED METHODS Encapsulation is Hiding data! Encapsulation is hiding process; hence then you hide the data. Not vice versa
  • 20. Encapsulation Contd..Encapsulation Contd.. See Program YCLASS_ENCAP_DEMO (TRZ300) DEFINITION IMPLEMENTATION
  • 21. InheritanceInheritance Inheritance is the process of creating new classes, called derived classes or subclasses or child classes from existing classes called base classes or super classes or parent classes. The derived class inherits all the capabilities of the base class but can add refinements of its own. The base class is unchanged by this process. VEHICLEVEHICLE accelerate() show_speed() PLANEPLANE accelerate() show_speed() rise() TORPEDOTORPEDO accelerate() show_speed() sink() FIGHTER JETFIGHTER JET accelerate() show_speed() rise() launch_missile()
  • 22. Inheritance Contd..Inheritance Contd.. Syntax for creating sub classes (local): See Program YCLASS_INHERT_DEMO (TRZ300) For global classes, go to transaction SE24 -> properties tab and define the super class.
  • 23. PolymorphismPolymorphism Polymorphism is a characteristic of being able to assign a different behavior or value in a subclass, to something that was declared in a parent class. VEHICLEVEHICLE accelerate() show_speed() PLANEPLANE accelerate() show_speed() Redefinition TORPEDOTORPEDO accelerate() show_speed() Redefinition
  • 24. Polymorphism Contd..Polymorphism Contd.. See Program YCLASS_POLY_DEMO (TRZ300) (Using inheritance) Method Redefinition
  • 25. ConstructorConstructor A constructor is a special method which is automatically executed by the runtime environment. They are used to set an object dynamically to a defined initial state. There are two type of constructor 1. Instance Constructor They are called once for each instance after the complete creation of the instance with the CREATE OBJECT statement. 2. Static Constructor They are called in a program once for each class before the class is accessed for the first time.
  • 26. Call components (static + instance)Call components (static + instance) • Attributes Call instance attribute of an object Static attribute of an object oref->attr Static attribute of a class class=>attr Its own instance attribute Its own static attribute me->attr OR attr • Methods Call instance method of an object Static method of an object CALL METHOD oref->meth Static method of a class CALL METHOD class=>meth Its own instance method Its own static method CALL METHOD me->meth OR CALL METHOD meth
  • 27. Interfaces • Interfaces extends scope of a class by adding there own components to the class. • Interfaces can only be defined in ‘PUBLIC SECTION’ of class definition. • Interfaces do not have an implementation part or instance. • Interfaces can be implemented by different classes and its methods can be implemented differently in each class. • Interface components can be called directly after assigning class reference to interface reference. (<iref> = <cref> )
  • 28. Type of InterfacesType of Interfaces • Local Interface • Global Interface
  • 29. Local Interface Interface <intf> Method meth1 Endinterface Class <class> definition PUBLIC SECTION Interfaces <intf> METHODS : meth1 Endclass Class <class> implementation method <intf>~meth1 endmethod method meth1 endmethod Endclass 1. Define Interface 2. Declare in class 3. Implement Interface methods
  • 30. Local Interface Alias Aliases are short names given to methods of interfaces for easy access. Interface <interface> Method method Endinterface Class <class> definition Interfaces <interface>. Aliases : m1 FOR <interface>~method Endclass CALL METHOD <class>->interface~method. CALL METHOD <class>->m1.  
  • 31. Interface Contd.. Both local and global interfaces can be accessedBoth local and global interfaces can be accessed using the following waysusing the following ways Class reference variable CALL METHOD <cl>CALL METHOD <cl>->-><intf>~<meth><intf>~<meth> • Using alias : CALL METHOD <cl>CALL METHOD <cl>->-><meth><meth> Interface reference variable <intf>= <cref> (class reference) CALL METHOD <intf>CALL METHOD <intf>->-><meth><meth>
  • 32. Interface Contd.. • For static components only CONSTANT can be accessed using interface name <intf>=><const> • Other STATIC COMPONENTS cannot be accessed using interface name but only through class. Access static attribute <class>=><intf~attr> Access static method CALL METHOD <class>=><intf~meth>