abap objects theory
TRANSCRIPT
-
8/8/2019 ABAP Objects Theory
1/21
ABAP Objects
-
8/8/2019 ABAP Objects Theory
2/21
What is OO?
Pillars of OO
Abstraction
Encapsulation
Inheritance
Polymorphism
Building Blocks
Agenda
-
8/8/2019 ABAP Objects Theory
3/21
What is OO?A brief comparison with Procedural
programming methodology
Object-orientation is a design &programming methodology to solve
problems considering real world objects.
-
8/8/2019 ABAP Objects Theory
4/21
Why OO?Complex software systems become easierto understand, since anobject-oriented architecture resembles reality more closely than otherprogramming techniques.
Changes in object-oriented systems should bepossible locally (at classlevel), without furtherchanges being necessary in otherparts of thesystem. This reduces the amount of maintenance required.
Polymorphism and inheritance enable many individual components tobe reused.
Object-oriented systems require less adjustment and maintenance,because the majority ofproblems can be discovered and corrected inthe design and development phases.
-
8/8/2019 ABAP Objects Theory
5/21
Pillars of Object-OrientationAbstraction Extracting the essential details, while ignoring
the unessential details
Encapsulation Enclosing all parts ofan abstraction in a
container(Information hiding)Inheritance Inheriting the abstraction from the existing ones.
Polymorphism Exhibiting different behaviorin different
situations
-
8/8/2019 ABAP Objects Theory
6/21
Building BlocksClasses
Objects
Interfaces
Events
Exceptions
-
8/8/2019 ABAP Objects Theory
7/21
Classes A class forms the basic abstraction ofareal-
world object.
It has certainproperties and behavioras describedby its components.
It is a blue-print to create any numberof objects
whichare of this classs type.
-
8/8/2019 ABAP Objects Theory
8/21
Classes (contd)
Private
access
Private
components
Flight
Address
Passenger-
list
Customer
Public
access
Interface
Public
events
Public
attributes
Public
methods
BOOK
Airline
Flight number
FLIGHT
-
8/8/2019 ABAP Objects Theory
9/21
Classes (contd) EncapsulationIt implies that all thepropertiesand behaviorofa class must be encapsulated in asingle container.
It restricts the visibility of the resources (attributesand methods) to the external world.
Theproperties and behaviorare thus enclosedwithin the class boundary.
It also forms an interface to the outside world.
You need to haveprivileges that the class dictatesto access anything inside this boundary.
-
8/8/2019 ABAP Objects Theory
10/21
Classes (contd) As defined earlier, each class is defined by its
properties and its behavior. These form the
members of the class.
From aprogrammingperspective,properties are
defined by attributes orthe data variables and
behavioridentified by methods.
You need to haveprivileges that the class dictatesto access anything inside the boundary.
-
8/8/2019 ABAP Objects Theory
11/21
Objects An Object is the instance ofa class.
It represents the class in real-world and exists real-time. Every instance has a unique identity and itsown attributes.
An objects life cycle is limited to the life of theprogram it is run whereas a Class can exist out oftheprogram (as it is defined in the Class
Repository). At any givenpoint of time, the state ofan object is
defined by the state of its attributes.
-
8/8/2019 ABAP Objects Theory
12/21
InheritanceThe concept that makes class hierarchiespossible.
A class can inherit its behaviorfrom anotherclass wherethe inherited becomes the sub-class and the inheritant the
super-class.The inherited class has all the behaviordefined by itssuper-class and in addition can exhibit new behavioraswell as override the functionality defined in the super-class.
A class can thus inherit from many classes (MultipleInheritance).
It essentially is a is-a relation between twoclasses/objects.
-
8/8/2019 ABAP Objects Theory
13/21
Inheritance (contd)But Inheritance is aproblem at times??!!
The Class Diamond Problem.
And..The solution is..
-
8/8/2019 ABAP Objects Theory
14/21
InterfacesInterfaces define a contract witha class as whatto define and not how to define.
Provides a template describing the skeleton foraclass (It tells us what this class is upto but it wonttell us how does it achieve).
It means, simply, it does not contain any definitionorimplementation of the behavior.
It is now left to the class how it defines thatbehavior.
-
8/8/2019 ABAP Objects Theory
15/21
Interfaces (contd)How then does it solve the problem of multipleinheritance?
Ans: Since an interfaceprovides only a template, aclass canpropose to implement multipleinterfaces therebyproviding the concreteimplementation forthe behaviorsuggested in theinterface.
This leads to anotherimportant concept calledPolymorphism.
-
8/8/2019 ABAP Objects Theory
16/21
PolymorphismDef: Itis the capability ofassumingdifferentforms.
Otherwise in OO terms, it is the ability ofa singleobject (in general methods) to exhibit differentbehaviorin different situations.
Identical (identically-named) methods behavedifferently in different classes.
A method from the same interface implementeddifferently in two different classes behavedifferently though theirorigin is same (from thesame interface).
Addressing the method remains the same whereas
-
8/8/2019 ABAP Objects Theory
17/21
Access SpecifiersA class restricts the access of its members oritselfby specifying the access rights.
These could be eitherof public, protected orprivate.
Apublic access enables any otherclass to accessall thepublic accessible members.
Aprotectedaccess restricts access only to the sub-classes that inherit from this class.
Aprivate access restricts the usage ofany memberonly to thisparticularclass. In otherwords, themembers definedprivate are invisible to the
outsiders.
-
8/8/2019 ABAP Objects Theory
18/21
Object Communication (Part I)Objects communicate with each otherthrough the
interfaceprovided by the class.
However, it is subjected to the restrictionsimposed by the classs interface.
In general, objects communicate using messages
(otherwise synonymously termed as method calls).
Theparameterspassed to the method forms themessage.
-
8/8/2019 ABAP Objects Theory
19/21
Object Communication (Part II)Events:
It is the ability ofan object to notify the externalworld ofany change in itself.
Event semantics:
An event is triggered, based on apre-definedcondition (forex. A change in an attributes valueoran unexpected state of the object) and this eventis handled by an event handler.
Event is defined to be raised by a method.
-
8/8/2019 ABAP Objects Theory
20/21
Object Communication (Part II)
(contd)And any interested party can handle thisevent by defining a method as an eventhandler.
The handlercould be the same class oranyotherinterested class.
Any external entity interested in listening to
the event should register itselfas thehandlerto that event in that class.
-
8/8/2019 ABAP Objects Theory
21/21
ExceptionsAn Exception is an undesirable state ofan
object.
If the execution ofapiece of code isidentified to possibly behave erratically,
then it should be identified as an exception
and should be readily handled if it occurs.