0% found this document useful (0 votes)
82 views111 pages

OOPS ABAB

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views111 pages

OOPS ABAB

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 111

OOPS ABAP

Why OOPS? Drawbacks of the procedural


programming
1. Encapsulation and hence improved 1. Security Issue
Security
2. Handling Large Project – To maintain
2. Abstraction Code Redundancy is the large number of source code is very-
3. Inheritance going to be very difficult
optimized Subroutine
4. Polymorphism Function Module
Readability and
5. Modularization 3. All the main features of OOPS are not
Maintainability
available listed in left
6. Design Pattern - Factory Design Pattern,
Façade, Single Design
What is the Benefits of Modularization?

1. Large set of code is going to be converted into small set of


code
2. Less work force and less time
3. Hence Cost is less
4. Better Maintainability
What is the important properties of OOPS ABAP ?

1. Encapsulation – 2. Data Hiding 3. Abstraction: 4. Inheritance 5.


Grouping of In OOPS we can Hiding the Polymorphis
attributes and easily achieve the method a) Multiple m
methods together DATA hiding concept Implementatio b) Multilevel
To achieve this we How? n Inheritance 1. Overriding
have the concept of Visibility set on the 2.
Class data: Overloading
Public
Protected
Private
What is Class in OOPS ABAP? VVI

Class is a User Defined Data type having component in form of attributes and Methods, events,
interfaces and they are bundled together.

In C++ In Java ABAP

Class is combination of data Class -> Instance Variables Class -> Attributes
members + Member functions + Methods + Methods
+ Interfaces
+ Events
+ Aliases
How many different types of Class in OOPS ABAP?

Class

Global Class –
It can be accessed in any of the
Reports/FM/Methods if its visibility Local Class–
sets to Public It is created inside a report and
accessed in that report only
T-Code: SE24( Class Builder )
Global class is accessible in any Its scope is specific to the program
program where it has been written.
What is Static and Instance Attribute? VVI
90
Math=>sta_sub( exporting .. Importing )
Class MATH

10 15

Insa1, insa2 Obj1 INSa1 INS_Add

INSa2

STA_Sub
STAa3
Insa
1 Insa2 Obj2
20 30

Obj1->staa3 = 20
Obj1->insa1 = 10 Obj1->staa3 = 40
Ojb1->insa2 = 15 Obj2->staa3 = 90

Obj2->insa1 = 20
static Attribute: Instance Attribute: CL_ABC

Accessed - Through Class name and IA1 IA2 SA3


Accessed - Only through the object OB1
Object instance =4 =5 =6
instance
1000 2000 3000

Memory – It is specific to class and Memory - OB2 1100 1200 3000


always points to same Memory WRITE: OB1->IA1 =4
location WRITE: OB1->IA2 =5
OB3 WRITE: OB1->IA3 =6 3000

Ob1->ia1 = 4.
Ob1->ia2 = 5. WRITE: OB2->IA1 =4
ob1->sa3 = 10 WRITE: OB2->IA2 =5
ob2->ia1 = 1000. WRITE: OB2->IA3 =6
Ob2->ia2 = 2000.
Ob2->ia1 = 30000.
Ob2->sa3 = 9999.
What is Object?
Object : Instantiation of the class. New Syntax(NW7.40)
To Create Object –( Instantiation of the class ) DATA (ob1) = NEW cl_sample()
1. Reference of the class – Naming the address in memory where your object will sit :
data: go_obj1 TYPE REF TO CL_ABC.
1. Create the object ( Instantiation )- DATA(go_obj1) = NEW CL_ABC( ).
CREATE OBJECT go_obj1

Level 1
ZCL_VEHICLE.
Protected: color
Zcl_Dealer
color

Level 2 ZCL_CAR.
Protected: color

Level 3
ZCL_SUZUKI.
ZCL_A ZCL_B ZCL_C

Oops abap doesn’t


upport the multiple ZCL_D
nheritence
What kind of inheritance is being supported by SAP ABAP?

Ans. Only Multilevel Inheritance is being supported by SAP ABAP

Q. If Multiple Inheritance is not supported, is there any way that it can be achieved?

Ans. Using the Interface we can achieve the Multiple Inheritance.


What is SUPER Key word? ZCL_VEHICLE. Note: With the help of SUPER key word very first implementation of the
Method RUN method of immediate super class is called.
WRITE: ‘CAR RUNS’
Ans. It is used to access the Immediate Parent ENDMETHOD.
Class Accelerate ( )
Protected: color

ZCL_SUZUKI.
Protected: color
METHOD RUN.
ENDMETHOD.
Output:-

ZCL_CAR.
Protected: color
METHOD DUMMY
SUPER->RUN( )
ENDMETHOD.
What are the different types of Inheritance?
ABSTRACT CLASS
INTERAFACE
ZCL_VEHICLE
ZCL_ANIMALS
ZCL_LIVING
ZCL_ORE

1. This can also be not instantiated.


Notes: -
1. Abstract Class can’t be
instantiated.
2. At least one method must be
abstract.
What is the difference between Abstract Class and
Interface? (VVI)
Abstract Class Interface
1. Abstract class must have at least one 1. All the methods of the interface must be
empty method( Abstract Method ) empty.

2. We can go for it if we know some of the 2. We can go for it if we don’t know any of
behavior( method ) in advance the behavior.

3. You can’t achieve multiple inheritance 3. Multiple inheritance with the help of
with the help of Abstract Class Interface can be achieved.
What is Constructor? Definition:
CONSTRUCTOR Special method To set the state of an Object/
And what are the different types of
Constructor? Special method To initialize the Variable of the
object/Class
CONSTRUCTOR/INSTANCE
CONSTRUCTOR/OBJECT CONSTRUCTOR
STATIC CONSTRUCTOR/CLASS
CONSTRUCTOR
What is the difference between Class Constructor and Instance Constructor?

Class Constructor(CLASS-CONSTRUCTOR) Instance Constructor(CONSTRUCTOR)

1. It is called only one time whenever a static 1. This is going to be called every time whenever you
component of a class is accessed or object is created. create the object of the class

2. Name of the class constructor: 2. Name: CONSTRUCTOR


CLASS_CONSTRUCTOR

Can a Constructor have a Import and export parameter both?

Ans. No Not possible. It is only having the import parameter.

When the constructor is going to be called – Before object creation or After object Creation?
Ans. Before Object Creation
What is the rule for Static Constructor?

Rule for Static Constructor:

1. If any object is created then very first time class constructor will be called.
2. If in the program any static component of the class has been accessed then
while loading the event in which that code has been written which is accessing
the component.
3. Same thing is true for Subroutine and Module.

CL_ABC PROGRAM ZABC.


SC1 – STATIC ATTRIBUTE
SC2 - STATIC METHOD *CL_ABC=>SC1 Lower
Event
DATA: OB1 TYPE REF TO ZABC.
CREATE OBJECT OB1.-2
DATA: OB2 TYPE REF TO ZABC
subroutine Higher
CREATE OBJECT OB2.
What is Static Method and it’s prosperities

What is the syntax to access the static method in the Inside a static method can you use the instance component of a class?
program? No – Not possible

Ans.->
This is first way using the class name -> CLASS NAME => Is it possible to override(redefine) the static method in the subclass?
Static Method Name Ans -> No not possible
Data: ob1 type ref to CL_ABC.
CREATE OB1 Why We are supposed to create or use the instance component(
Ob1->Static Method method, attributes, events) over static component?
Ans. – Because we can’t use the polymorphism which is one of the
Then, when to use Static Method?

Every time we don’t require polymorphism for example in case of Factory method.

When we have to create the test program we can go for it because accessing the
method is very easier here

Class Name => Method.

Polymorphism

Overriding=>Same Definition( Same


Overloading
signature / parameter )
Polymorphism( Different Form)

Overloading Overriding

Class:-
Mehtod : run ->1
Method : run importing x type i. ->2
Method : run importing y type char5. ->3
Method: run importing x type I z type I
exporting y time char10. ->4

Obj->run( 5 )
Obj->run( ‘5’ )
Obj->run(5,6)
Q. Can a Class Constructor will b
Polymorphism and Inheritance inherited?
Ans. No
Q. Can a Constructor will be
inherited
->Class Constructor can never be inherited. Ans. Yes .
Q. Can a constructor will be
redefined?
->Constructor can be inherited and can not be redefined but a subclass Ans. No.
can have its own constructor but must use the SUPER-CONSTRUCTOR.
Q. Can a subclass have its own
constructor defined?
Ans. Yes.

If a subclass have a constructor redefined then is it necessary to call the super-


>constructor in the redefined constructor?

Ans.-> We must have to use the SUPER Key word .


Friend Key word / Friend Class

If a class A is friend of Class B, then Class A can access the Protected or Private component ( attributes,
Methods and Events)
Of Class B.

CLASS A FRIEND CLASS B


Local Class SE38

1. Local class is created inside the Program.


2. The Scope of the local class is just inside that program
3. You can create the Global class from Local Class

What is the major / Important / basic / fundamental difference between Friend Class
and Subclass.

Friend Class -> public, protected , private , no polymorphism.


Subclass->Public and protected. Polymorphism.
Agenda:
1. Load Key Word( Obsolete Key Word )

Report zdummyloaddemo.
class zcl_eb22_vehicle DEFINITION load.
" Whenever you are going to access the static component of the class
zcl_eb22_vehicle=>test_static( ).

1. Deferred Key Word

What is Deferred Key word?

Ans. Just to let the compiler know that the used class is somewhere declared later in the program.
Q. What is Interface?

Ans. A user defined data type which has below property -


• It doesn’t have the implementation of any method.
• It have only the method definition.
• It can’t be instantiated.
What is Abstract Class and Interface? What is the Similarity and difference between Both? (VVI)
Ans –
Abstract Class Interface
Similarity – 1. As its name suggests, it is an 1. Similarity - This also can’t be
abstract, not concrete, so This class can’t be instantiated. This is also used to achieve
instantiated, If you try to instantiate in ABAP polymorphism by
editor it’ll throw you an error. This is Overriding/redefinition.
similarity. It’s also used to achieve
polymorphism through 2. Power of polymorphism can be
Overriding/Redefinition. realized with the help of narrow casting.
2. Power of polymorphism can be
realized with the help of narrow casting.

Note – Exception is Static method. This


can’t be overridden/redefined,
because its all the attributes are
static which share the same
Constructor Hierarchy Made Easy

Q. When you create the Object of the Subclass in below scenario in what sequence call will take place?

CREATE THE OBJECT OF THE SUBCLASS:


SUPER CLASS
CLASS_CONSTRUCTOR And below is the Sequence -
INSTANCE CONSTRUCTOR
SUPERCLASS-> CLASS CONSTRUCTOR

SUBCLASS -> CLASS CONSTRUCTOR


SUB CLASS
CLASS_CONSTRUCTOR SUBCLASS-> Instance Constructor
INSTANCE CONSTRUCTOR
SUPER->CONSTRUCTOR SUPERCLASS-> Instance Constructor
}
Sequence in which objects are called
UML : Unified Modeling Language
Narrow Casting
Wide Casting What is UML Diagram?

Ans. UML: This is standard pictorial/graphical representation of denoting the components of a class and its
relationship between one or more than One Classes.

Cl_Anilmal
Attributes(Color,
Category)
Methods(run, sleep)

Cl_cow
+ total_milk
Methods(eat_grass)
How to represent Class via UML diagram. What is the meaning of symbol “+”, “-” and “#” and “________”
Ans – Below is the detail

Please watch out this video: https://www.youtube.com/watch?v=UI6lqHOVHic

Italic Represents the Abstract.


+ Public

CL_ANIMAL CLASS NAME - Private

# Protected

+ color _____ Static


+No of foot
+ height
+No of eyes CLASS ATTRIBUTES
- No of horn

# animal Type

+ set foot ( )
+ get foot ( )
CLASS METHODS
- run ( )
# awake ( )
What is association relationship, aggregation relationship and composition relationship in OOPS
Ans. – Association: is a USING relationship where all objects have there own lifecycle and there is no owner. E.g. (
Relationship between Teacher and Student, Doctor and Patient etc.
Aggregation: is a HAS A relationship which is specialized form of Association. Objects have their own lifecycle
but only one of the objects will be owner. E.g. Teacher and School, Company and employee, District and people(District
Magistrate) etc.
Composition: is a MUST HAVE relationship which is again a specialized form of aggregation where one object
life cycle is completely dependent on another object. E.g. Building and Room, Plane and Wings, Body and Mind etc.

ASSOCIATION

AGGREGATION

COMPOSITION
Casting
Data: lv_age_i type int4.
Data: lv_age_c type char5.

Narrow Casting Wide casting Lv_age_c = ‘23’.

Narrow Casting: Assigning the object of a sub class Wide Casting: Assigning the object of lv_age_i = Lv_age_c
to The reference of the super class is known as Super class to the sub class
Narrow Casting Condition: Before performing the Wide
Casting we must have to perform the
Narrow Casting
?= Lesser Perspective animal
Animal NARROWER

Ob_animal = ob_cow”narrowcasting.
Ob_cow ?= re_ob_Animal “widecasting

COW WIDER SIDE


Wider Perspective
Animal

Cow
Q1. What is the different types of casting in OOPS in terms of inheritance(i.e. Super Class vs Sub
class)( VVI )

Ans – There are two types of casting –


1. Narrowing Cast and other is
2. Widening Cast

Q2. What is narrowing Cast? Explain in detail ( VVI )

Ans. Assigning of instance of subclass to the reference of Superclass.

SUPER CLASS – Narrower/Lesser Perspective, General Detail

SUBCLASS – Wider Perspective, More Detail


Q3. What is Widening Cast. Explain in Detail

Ans. Assigning the object instance of super class to the subclass. i.e. you
are going from lesser perspective to wider perspective

Super Class -> Common Detail, Lesser information,


Lesser perspective

Sub Class– More information, More method, More properties,


More Detail
How you can achieve the multiple inheritance? (VVI)

Ans.-> With the help of Interface we can achieve this.


EVENTS in Procedural ABAP

Classical Report:
LOAD-OF-PROGRAM
INITIALIAZATION
AT SELECTION SCREEN
AT SELECTION SCREEN OUTPUT

Interactive report:
AT USER COMMAND
AT LINE SELECTION

Module Pool:
PAI
PBO
POH
POV
Events
An event is an action used for providing dynamic features to applications.
1. Create an Event
2. Create a Method to handle the Event( Event Handler Method)
3. Set up the linkage between Action and Event handler method
4. Register the Event
5. RAISE the Event in a separate Method
6. Create Program and from there call the method in step 5

Functionality
ACTION (Method)
(Event) HITTHEDOG BARK()
Event Handler Method

Method
Raise EVENT
RAISE HITTHEDOG
Event Method

Q. How a method is triggered when an event is fired in OOPS

Ans. -> We must have to register the method with the events

SET HANDLER <METHOD> FOR <ALL INSTANCES/SPECIFIC INSTANCE)

EVENTS : <EVENT_NAME> EXPORTING <PARAMETER NAME>.


METHOD:
Summary for Events
Events with Parameter and Event handler Method
• An Event can have only Export Parameter.
• It will be only pass by value. Pass by reference is not supported.
• All the export parameter of the events can be there as import parameter of the EVENT HANDLER method
• Event handler method importing parameters can’t have types

SYNTAX(EVENT):
EVENTS: hit_the_dog EXPORTING VALUE(im_event) TYPE i .

SYNTAX(EVENT HANDLER METHOD)


METHODS: barking FOR EVENT hit_the_dog OF cl_event_raiser
IMPORTING im_event [sender] .
“Here type for im_event is not required.

Note: 1. Here sender is only possible in case of instance method.


2. Sender parameter contains the reference of triggering Class
EVENTS – FOR ALL INSTANCES

SYNTAX:
SET HANDLER go_event_handler->weeping FOR ALL INSTANCES .

Note: FOR ALL INSTANCE addition is only valid for INSTANCE EVENT

Sender parameter

1. Here sender is only possible in case of instance method.


2. Sender parameter contains the reference of triggering Class
EVENTS – DEREGISERATION AND REREGISTERATION
How to Deregister:
SET HANDLER go_event_handler-
>barking FOR ALL INSTANCES ACTIVATION abap_false.
OR
SET HANDLER go_event_handler-
>barking FOR ALL INSTANCES ACTIVATION space. .

How to Register:
SET HANDLER go_event_handler-
>barking FOR ALL INSTANCES ACTIVATION abap_true.

Note: If you don’t specify ACTIVATION abap_true then also no problem. By default it takes.
One Event : Multiple Handler Method
• One event can have multiple handler method.
• It gets executed in the same sequence in which it is registered.

METHODS: barking FOR EVENT hit_the_dog OF cl_event_raiser IMPORTING


im_event sender ."barking is event handler method

METHODS: weeping FOR EVENT hit_the_dog OF cl_event_raiser.

What syntax/command need to be used to trigger the


method? method1
Ans. -> RAISE <EVENT NAME>

Click
Method2
STATIC EVETNS

Static Events Can be raised inside the Instance Method or static Method.

Main Difference:
While registering the handler we have to use only

SET HANDLER <HANDLER METHOD>.

We don’t have to give the “FOR” because it’s static event.


Static Event can be raised from instance Method as well as Class Methods

Note: Inside the Static Method, Instance Event can’t be raised.


QUESTIONS: Give the Answers

Q1. Can u raise the static event inside the instance method? Yes

Q1. Can u raise the Instance event inside the instance method? Yes

Q2. Can u raise the instance event inside the static method? NO

Q3. Can a handler method be Static or Instance? Yes

Q4. Does the handler method depend on Event type( Static Event or Instance Event ). No
EVENTS

INSTANCE EVENT STATIC EVENTS

Parameters:
Registration 1. SET HANDLER <HANDLER Method> for 1. SET HANDLER <HANDLER METHOD>
<object> /<ALL INSTANCES>

Method 2. Only inside the instance Method 2. Inside the instance method and Static
In which type method
of the method
event will be
raised?
3. Supported 3. Not Supported
Sender
reference
What are the Different types of Exception?

Ans. There are two types of Exceptions -

EXCEPTION

NON - CLASS BASED


CLASS BASED EXCEPTION
EXCEPTION

CX_SY_ZERODIVIDE
EXAMPLE: MYOWNEXCEPTION

What is the very first class/root class for exception Class?


Ans. -> CX_ROOT.
What are the different types of Custom Exception Class?

Custom Exception Class

OTR Based Message Message Class Based


OTR => Online Text Repository Message
What is the use of CLEANUP Block? (VI)
Ans. To free the memory / internal / external resources.

CLEANUP.

AJK

AJKLDSFJL
LJKALDSF

ENDCLEANUP.
What are the different types of Object Services ?

Object Services

Persistence Services Transaction Services Query Service


Persistence Service/object VVI

Persistence data Transient Data (Non-Persistent Data)

The data which is going to be held only


The data which persists permanently in the
during the runtime of the program that
system is known as persistent data.
is known as Transient Data.
e.g. Internal table, variable, work area
DML
MODIFY <DB> FROM <WA>/ <TABLE table>
INSERT <DB> from <WA>/ <TABLE table> Report ZPKTEST.

If you want to store the state of the


object(data object/Class object =>
wa/internal/var/Instance object) permanently
in the db in the OOPS way we have the
Persistence service
Persistence Class Detail

Base ( Agent Class )


=> Abstract
Protected ( Persistence Class )
Base class will be friend
of persistence class ZCB_DEMO

ZCL_* OR YCL_*
PROTECTED

Actor Class( Private Class )


Agent( Public Static )
ZCL_DEMO

ZCA_DEMO
You require a database which is going to save the data.
DML

For Detail : https://youtu.be/Erh5EuPCtt4


Singleton Design Pattern VVVVI -
Use Case / Problem Statement -> How to deal with a logger Class

Singleton Design Pattern –


Single(Only one) + Ton( Instance )
1. It will help you get the same object every time. It will not allow you to
instantiate a class multiple time.

Steps to create the Singleton Design Pattern:-


1. Define the class as a Private
2. Define one Method : Public + Static with a returning parameter of type ref
to the same class.
3. Define the Attribute of type ref to the same class: Private + Static – which
will hold the instance of the class
4. Write the logic inside the method
IF <ATTRIBUTE> is bound.
<RETUNING_PARAM_OF_METHOD> = <ATTRIBUTE>.
ELSE.
CREATE OBJECT <ATTRIBUTE>
<RETUNING_PARAM_OF_METHOD> = <ATTRIBUTE>.
ENDIF.
SINGLETON PATTERN – Logger Class Example Report ZLOGGER

ZCL_EMPLOYEE
Id, ZCL_LOGGER O_LOGGER-
Name SET_DATA( ): >PRINTLOG()
ZCL_LOGGER PRINT_MESSAGE( ):

If all the employee data and company data is


ZCL_COMPANY successfully received from program in that case
Company_name you have to log the successful message.
Department If any of the data is not logged, in that case
ZCL_LOGGER Log the unsuccessful message.
Example for Singleton Pattern
Passenger Class
-----------------------
Attributes:
PASSENGER_ID,
AGE
-------------------------------- Booking Class
Methods: ---------------------
+SET_DATA() PASSENGER_ID,
+SET_DATA_FOR_BOOKING() AGE,
Carrier,
Connection,
Flight Class -----------------------
+SET_DATA()
Attributes: +BOOK_TICKET()
Carrier,
Connection
------------------------
Methods:
+SET_DATA()
+SET_DATA_FOR_BOOKING()
Factory Design Pattern

This comes under the category of creational Design Pattern

It is used to hide the complexity of object creation and produces the object on
demand
Design Pattern

Creational Design Pattern Structural Design Pattern Behavioral Design Pattern

Adapter Design
Singleton Design Interpreter Design
Bridge
Factory Design Pattern Iterator design pattern
Composite
Singleton Factory Design Mediator
Pattern Decorator
Observer Design Patter
Object Pool Façade
Visitor Design Pattern
Prototype Flyweight
Command Design Pattern
Abstract Factory Proxy
State Design Pattern
MVC – Model view Controller

Model: Data Provider Spring -> MVC Design pattern


SAP UI5 -> MVC Design Pattern
View: Interface FIORI -> MVC Design Pattern

Controller: Actual Logic/Business Logic/ Data Manipulation


Proxy Design Pattern

• Sometimes you need to delay the instantiation of the object because it may be very costly to instantiate as it
may take large amount of resources as memory and CPU without having any fruitful result. It will take extra
time as well

• Why we don’t get fruitful result because we may have bad data, which may further stop processing.

• Hence it’s always better to first validate all the required data in a separate class

• This another class is known as proxy class because it gets executed first, in stead of actual class.

➢ Proxy class is light weight class. Very- very heavy class- excel,
➢ It hold the implementation of validation logic outlook,
➢ If validation is successful then only go and create the sap heavy class.
actual/heavy class object and execute the functionality.
Proxy Design Pattern Implementation

Caller Interface/abstract design

Proxy Class Actual Class( Heavy Class )


Note:-

Generally proxy design pattern is used in ABAP when we have to instantiate the NON ABAP object.

Because, NON-ABAP objects are very heavy ( e.g. EXCEL object and OUTLOOK object )
Adapter Design Pattern

1. Adapter converts the objects which are incompatible due to the difference in the interface. By
Implementing the Adapter, we can allow classes to work together, which can’t work without Adapter.
2. Sometimes we come across the scenario where client expects to have certain interface. Already we have an
object which is satisfying the client need then why to create the another object. We can create a wrapper
and use it.

3. In real time we have USB Adapter, Wi-Fi Adapter etc.

How to run a function module in Batch Job?

You already have a function module to sum( say ), and your client came
up with need to pass the parameters – How to do?
Adapter Design Pattern Implementation

Caller Interface(Target)

Adapter Adaptee
Facade Design Pattern

Facade is a French word meaning – face or frontage

Consider a scenario where your team is developing a big application. Application have been
divided into different parts and assigned to different DEVELOPERS.

Now suppose , every one has to handle the message in that application different languages.

So here everyone would end up with there own function module or methods for displaying the
message or capturing the message.

So what is solution: Façade : So Team can decide to create a single function module / Method
which will handle the message and this FM/method can be used by everyone. Now tomorrow if
some extra addition need to be done related with message, that single FM will be the place where
one can go and change and communicate to other team members.
Façade Design Pattern

Complex logic
Source: Internet(sapignite.com)
Façade Design Pattern -> Google.come
Template Design Pattern

This pattern is required if two different components have significant similarities

Interface

Abstract Class

Class A Class B
Interface ZIF_VEHICLE_FUNCTION ZCL_VEHICLE: ( ABSTRACT CLASS,
Template Design Pattern CONCRETE CLASS OR INTERFACE )
1. RUN( )
2. ACCELARATE( )
ABSTRACT CLASS ( ZCL_VEHICLE )
3. SPEED( )
4. SOUND( )

ZCL_CAR ZCL_TRUCK ZCL_PLANE


Decorator design Pattern

MAIN
Decorator ( Decoration )

1. In Decorator design pattern we use the RDEFINITION of Existing method


MAIN CLASS( ABSTRACT ) Subclass
+DISPLAY_OUTPUT( ) REDIFINTION

ALV OUTPUT
STD_ALV CLASS DECORATOR CLASS PDF OUTPUT
DISPLAY_OUTPUT DISPLAY_OUTPUT( )

PDF CLASS
DISPLAY_OUTPUT
Decorator Design Pattern
1. When we require to extend the behavior of certain objects at run time then we
use the Decorator Design Pattern
2. This can be separate than the existing instances of the same class
3. This can be achieved by creating certain environment( Infrastructure ).

Steps to Follow to adopt the Decorator Design Pattern

1. Identify the common method and put inside the Abstract Class
2. Create a Decorator Class – This is nothing but subclass of the main class. This is
also called component
3. In the subclass( i.e. in Decorator Class ), create an attribute with type ref to Main
Class
4. Create a constructor in Decorator Class with importing parameter REF TO Main
Class. Set the attribute from this parameter
5. Redefine all other methods in decorator class inherited from Main Class. Just call
the same method using the reference of the main class
6. Create subclass of the decorator when a new behavior is required
7. Redefine the methods
8. Write the main logic using a helper variable of type ref to Main Super Class
Observer Design Pattern

Observer: One who observes

Event Will be taken place


Computer Device
ON_TEMP_CHANGED

Subject
Tablet Device
Weather Station Observer Class ON_TEMP_CHANGED
METHOD: TO TRIGGER THE ON_TEMP_CHANGED
EVENT
EVENT:
TEMPERATURE_CHANGED

Mobile Device
ON_TEMP_CHANGED

Observer
Composite Design Pattern( Structural Design Pattern)

Me

My Father My Mother

Grand-pa
Grand-ma Grandma
Grandpa
Computer(Composite Node )

Composite
Node Monitor Mouse
Cabinet
Leaf Node Leaf Node

Hard Disc CPU Leaf Node


Computer
Component

Cabinet
setPrice( )
getPrice( )

Hard Disc
getPrice CPU MotherBoard
setPrice( ) Get_Price
IT_HD_COMP setPrice( )

ram
garphics
RAWMAT SOFTWARE
What is Strategy design pattern?

Strategy Design Pattern


As per Wikipedia definition
In computer programming, the strategy pattern (also known as the policy pattern) is a behavioral software design
pattern that enables selecting an algorithm at runtime. Instead of implementing a single algorithm directly, code
receives run-time instructions as to which in a family of algorithms to use.
Strategy Pattern Soldier Game Development
Attack( )
Refill( )

Spearman Archer
Attack( ) Attack( )
Refill( ) Refill( )

Refill-> Pause for 5 seconds


Strategy Pattern Game Development
Soldier
Attack( )
Refill( )

Archer Gun Man


Spearman
Attack( ) Attack( )
Attack( )
Refill( ) Refill( )
Refill( )

Refill-> Pause for 5 seconds


Strategy Pattern
Soldier Game Development
Attack( )
Refill( )

Archer Gun Man Paladin


Spearman
Attack( ) Attack( ) Attack( )
Attack( )
Refill( ) Refill( ) Refill( )
Refill( )

Refill-> Pause for 5 seconds


Strategy Pattern Soldier
Attack( )
Refill( )
Repair( )

Robot
Palladian
Archer Gun Man Spearman
Spearman Spearman
Attack( ) Attack( ) Attack( )
Attack( ) Attack( )
Refill( ) Refill( ) Refill( )
Refill( ) Refill( )
Repair( )

Refill-> Pause for 5 seconds


Soldier
Strategy Pattern Attack( ) If_refill_weapon If_repair_weapon
Refill( )
Repair( )

Palladian Robot Iron Man


Archer Gun Man
Spearman Spearman Attack( ) Attack( )
Attack( ) Attack( )
Attack( ) Attack( ) Refill( ) Refill( )
Refill( ) Refill( )
Refill( ) Refill( ) extRepair( ) intRepair( )

Refill -> Pause for 5 seconds Repair -> Repair the Weapon
Gunman –> Time based feeling Robot –> External Repair
Archer -> Count based feeling Iron Man -> Internal Repair
Strategy Pattern Soldier If_refill_weapon If_repair_weapon
Attack( )
Refill( )
Repair( )

Palladian Robot
Archer Gun Man
Spearman Spearman Attack( )
Attack( ) Attack( )
Attack( ) Attack( ) Refill( )
Refill( ) Refill( )
Refill( ) Refill( ) Repair( )

Refill -> Pause for 5 seconds Repair -> Repair the Weapon
Gunman –> Time based feeling Robot –> External Repair
Archer -> Count based feeling Iron Man -> Internal Repair
If_refill_weapon If_repair_weapon
Strategy Pattern Soldier
refill( ) repair( )
Attack( )
Refill( )
Repair( )

Palladian Robot Iron Man


Archer Gun Man
Spearman Spearman Attack( ) Attack( )
Attack( ) Attack( )
Attack( ) Attack( ) Refill( ) Refill( )
Refill( ) Refill( )
Refill( ) Refill( ) Repair( ) Repair( )

Refill -> Pause for 5 seconds Repair -> Repair the Weapon
Gunman –> Time based feeling Robot –> External Repair
Archer -> Count based feeling Iron Man -> Internal Repair
Soldier
Strategy If_refill_weapon If_repair_weapon
Attack( )
Pattern
Refill( )
Repair( ) Count_based_refill Internal_repair External_repair
Time_based_refill

Robot Iron Man


Archer Gun Man Paladin
Spearman Attack( ) Attack( )
Attack( ) Attack( ) Attack( )
Attack( ) Refill( ) Refill( )
Refill( ) Refill( ) Refill( )
Refill( ) Repair( ) Repair( )

Refill -> Pause for 5 seconds Repair -> Repair the Weapon
Gunman –> Time based feeling Robot –> External Repair
Archer -> Count based feeling Iron Man -> Internal Repair
Strategy Pattern: Conclusion

1. This comes under the Behavioral Pattern

2. In this Pattern Class Behavior/algorithm Changes at run time

Hope you enjoyed ☺


Approach

1. Identify the changeable variable and take it out and put in an interface or Abstract Class
2. Encapsulate in family of algorithm separately in concrete classes
3. Client should be using these interface as references. Client should not implement it
Context/Client Class
ZCL_SOLDIER

-GO_REFILL : ZIF_REFILL_WEAPON
-GO_REPAIR: ZIF_REPAIR_WEAPON

Refill Strategy +attack( )


+dynamic_repair_selection Repair Strategy
+dynamic_refill_selection

<<interface>> <<interface>>
ZIF_REFILL_WEAPON ZIF_REFPAIR_WEAPON
+Refill() +Repair()

ZCL_Count_Based_Refill ZCL_Time_Based_Refill ZCL_Internal_Repair ZCL_Exteranl_Repair


+refill( ) Refill( )
Repair() Repair()
What is SOLID ?

Single-responsibility principle
Open-closed principle
Liskov substitution principle
subclass Interface segregation principle
Dependency inversion principle

Super class
SOLID This was given by author - Robert C. Martin ( Uncle BOB ) in Year 2000.
Definition:
This is very popular set of design principles which guides while developing a software in OOPS, what are
the important guideline need to be followed for better maintainability and reusability and flexibility. INTERFACE
It is mnemonic acronym for below set of principles - METHOD A,
S -> Single Responsibility Principle (SRP )
A class should have one and only one reason to change
A
O -> Open-Closed Principle
Open for Extension and Closed for Modification

L -> LISKOV Substitution Principle


Objects in a program should be replaceable with instances of their subtypes without altering the
correctness of that program

I -> Interface segregation Principle


In stead of generic Interfaces, we should have the specific Interface

D -> Dependency Inversion Principle => Depend on abstraction, not on Concretion


S->Single Responsibility Principle

RENAULT_CAR

KWID DUSTER
Open Closed Principle

Open for extension but closed for modification


Liskov substitution principle Animal
Sounds()

cat cow snail

C Hence in the above example as per LISKOV’S


principle rules are violating

The principle says that any class must be directly replaceable by any of its subclasses without any error.
Link: https://www.youtube.com/tch?v=ObHQHszbIcE

The Liskov substitution principle (LSP) is a specific definition of a subtyping relation created by Barbara Liskov and
Jeannette Wing.
D: Dependency inversion principle

Two points ->


• High-level modules should
not depend on low-level
modules. Instead, both
should depend on
abstractions (interfaces)

• Abstractions should not


depend on details. Details
(like concrete
One should depend upon abstractions, [not] concretions.” implementations) should
depend on abstractions.
Control Framework

Control in general:
✓ Controls are independent software component embedded in SAP GUI.

✓ Controls can be used to achieve extra flexible functionality.

✓ SAP supports ACTIVEX Controls for MS Windows platforms and JavaBeans for the SAP GUI in the Java environment.

✓ Control helps to improve the performance by –


having the data on the presentation server instead of application server( e.g. during scrolling and editing the texts etc. )

✓ Frequent data exchange on from Backend to Frontend and vice versa increase the load on the network and gives the bad experience
for user due to slowdown of the application

✓ Hence if most of the work is going to done at frontend only then control becomes useful.

Controls framework:
✓ It was introduced in Release 4.6
✓ CFW encapsulates all the controls in global classes of ABAP objects.
Controls

Application Controls Container Controls

This component is used inside This component is used to hold


the container controls to the application controls and
achieve a specific functionality provides the standard layout on
like displaying the html page, the screen
Text etc.
Each container controls must
be associated with the screen.
screen
Container Control

Application
control
Container Controls How to use:-
1. Create custom container in screen painter (say CONTAINER )
2. Pass the custom container name(CONTAINER) to create the object of the class
CL_GUI_CUSTOM_CONTAINER
CL_GUI_CUSTOM_CONTAINER. Say object name is O_CUST_CONTAINER
3. Call the application control object method by passing the custom control
object(O_CUST_CONTAINER) as parent

Note: do all this in PBO of the SCREEN

How to Use:-
1. While creating the object of this class must need to be linked with any one of the
CL_GUI_DOCKING_CONTAINER
edge of the screen.
2. That edge is now become Docker and can be used for the purposed of any
application control
Note: No Screen painter is required.

Splitting the screen area into vertical and horizontal section


CL_GUI_SPLITTER_CONTAINER That means splitting the screen into multiple parts
Control Framework
CL_GUI_CFW=>FLUSH
Automation
When you want to pass Controller FILTER Text Edit GUI
the message or instruction Presentation Server
before the PBO call of the
screen, we can use the
Automation
CL_GUI_CFW=>FLUSH.
Queue
APPLICATION
CL_GUI_CFW=>DISPATCH SERVER

When you want to trigger Control Framework


your Application EVENT
HANDLER METHOD before Automation Application Server
PBO call then you can use Queue
this DATABASE
CL_GUI_CFW=>DISPATCH.
What is the use of CL_GUI_CFW=>Dispatch? VVI
CL_GUI_CFW=>DISPATCH

When you want to trigger your Application


EVENT HANDLER METHOD before PBO call
then you can use this
CL_GUI_CFW=>DISPATCH.
What is the use of CL_GUI_CFW=>FLUSH VVI

CL_GUI_CFW=>FLUSH

When you want to pass the message or instruction before


the PBO call of the screen, we can use the
CL_GUI_CFW=>FLUSH.
Q . What are the steps need to followed to make a ALV editable? VVI

Ans. -> There are two scenario –

Case 1. When you have to make complete ALV editable -


For making the full ALV editable we have to pass LAYOUT-EDIT = ‘X’.
There is no setting required at field catalogue level.

Case 2: When you have to make a specific column editable.


But when you need to make a specific field/column editable then
We need to specify that column at field catalogue level and set EDIT property as ‘X’ like
Fieldcatalogue-EDIT = ‘X’.
Q . What are the steps need to be followed to color an ALV? VI

Steps need to be taken based on scenario –


Case 1. setting color for specific column.
When a specific column need to be colored then setting need to be done at FIELDCATALOGUE
level.
FIELDCATALOGUE-EMPHASIZE = Cxyz where x = Color Code,
y = Intensified On(1) or Off(0)
and z = Inverse on(1) or off(0).

Case 2. When a row need to be colored in ALV


Below steps need to be followed –
Step 1. Include a field(SAY ROW_COLOR) of type CHAR4 at last in structure which will hold
the color attribute.
Step 2. Make system aware that this field is to store the attribute for color by specifying
setting attribute INFO_FIELDNAME at layout level.

GD_LAYOUT-INFO_FIELDNAME = ‘ROW_COLOR'.
Case 3. Check the next Slide
Case 3. Color at cell Level
step 1. Include a field CELLCOLOR of type LVC_T_SCOL at structure in last.
Step 2. Inform to the program by setting the COLTAB_FIELDNAME attribute of LAYOUT that
the extra field CELLCOLOR is for the purpose of setting the color at cell level.
Do as below -
layout-COLTAB_FIELDNAME = 'CELLCOLOR'.
Step 3. Populate the final internal table where corresponding CELLCOLOR field need to
populated accordingly.
1. What is the Priority of the color for below Row Color, Column Color and Cell
Color

Ans. -> Below is the priority sequence -


1. Cell Color
2. RowColor
3. Column Color

MANDT MATNR MTART MATKL MBRSH


Q. Suppose you have to display the check box column for selecting the row from output ALV

Step1. Define one extra column(CHECKBOX_FIELD) of CHAR1 which will be used for check
box

Step2: - At fieldcatalogue level you have one attribute called ‘CHECKBOX’


FIELDCATALOGUE-CHECKBOX = ‘X’.
FIELDCATALOGUE-FIELDNAME = ‘CHECKBOX_FIELD’

You might also like