ABAP Objects - Introduction

Size: px
Start display at page:

Download "ABAP Objects - Introduction"

Transcription

1 ABAP Objects - Introduction ABAP Objects - A Workshop A Workshop from the ABAP Language Group Horst Keller SAP AG SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 1 SAP AG

2 Workshop Goals Position of ABAP Objects within the R/3 System Overview of the syntax of ABAP Objects Working with existing classes and interfaces Defining classes and interfaces Creating objects Reacting to events Understanding the polymorphism provided by interfaces and inheritance SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 2

3 Workshop Goals This is not a comprehensive course in objectoriented programming There is more to object-oriented development than just object-oriented programming. It has logical advantages that are independent of the concrete implementation. The most important (and most time-consuming) part of a real object-oriented application is the object-oriented modeling. The OO Rollout Group provides another ABAP Objects course SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 3

4 Contents Introduction From Function Groups to Classes Classes Objects Events Interfaces Inheritance Using Global Classes Exercises SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 4

5 Introduction Object orientation Objects ABAP Objects SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 5

6 Object Orientiation Data Data Data Data Data Attributes Data Abstraction Function Function Function Function Methods Data Method Method Method Function Function Function Function Functions and data Data model as an abstraction of the real world SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 6 Software objects Object model as an abstraction of the real world Real-world objects

7 Objects Interface Private access Private components Flight Customer Passengerlist Address Public attributes Airline Flight number Public methods BOOK Public access FLIGHT Public events SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 7

8 ABAP Objects ABAP Objects is isan anupwards-compatible extension of of the the existing ABAP language You You can can use use existing ABAP statements within ABAP Objects You You can can use useabap Objects within existing programs ABAP Objects is is fully fully integrated in inthe theabap Debugger SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 8

9 From Function Groups to Classes Instances of function groups as objects Example: Function group as counter SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 9

10 Instances of Function Groups as Objects Function group 1 Function group 2 Function module Data Function module Data ABAP program with data CALL FUNCTION Internal session of an ABAP program External session SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 10

11 Function Group as Counter - Definition FUNCTION-POOL COUNTER. DATA COUNT TYPE I. FUNCTION SET_COUNTER. * Local Interface IMPORTING VALUE(SET_VALUE) COUNT = SET_VALUE. ENDFUNCTION. FUNCTION INCREMENT_COUNTER. COUNT = COUNT + 1. ENDFUNCTION. FUNCTION GET_COUNTER. * Local Interface: EXPORTING VALUE(GET_VALUE) GET_VALUE = COUNT. ENDFUNCTION. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 11

12 Function Group as Counter - Call DATA NUMBER TYPE I VALUE 5. CALL FUNCTION 'SET_COUNTER' EXPORTING SET_VALUE = NUMBER. DO 3 TIMES. CALL FUNCTION 'INCREMENT_COUNTER'. ENDDO. CALL FUNCTION 'GET_COUNTER' IMPORTING GET_VALUE = NUMBER. NUMBER has value 8 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 12

13 Classes Generalize Function Groups nth instance, class m 1st instance, Daten class m Funktions- Data Interface baustein Data nth instance, class 1 1st instance, class 1 Daten Schnitt- Data Interface stelle Data ABAP program with data Internal session of an ABAP program External session SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 13

14 Classes, References, and Objects Example: Class as counter Reference variables Creating objects Calling methods Working with references SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 14

15 Example: Class as Counter CLASS counter DEFINITION. PUBLIC SECTION. METHODS: set IMPORTING VALUE(set_value) TYPE i, increment, get EXPORTING VALUE(get_value) TYPE i. PRIVATE SECTION. DATA count TYPE i. CLASS CLASS counter counter IMPLEMENTATION. METHOD METHOD set. set. count count = set_value. set_value. ENDMETHOD. ENDMETHOD. METHOD METHOD increment. increment. count count = count count ENDMETHOD. ENDMETHOD. METHOD METHOD get. get. get_value get_value = count. count. ENDMETHOD. ENDMETHOD. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 15

16 Reference Variables DATA: cnt_1 TYPE REF TO counter. CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 16

17 Creating an Object DATA: cnt_1 TYPE REF TO counter. CREATE OBJECT cnt_1 TYPE counter. 1<COUNTER> CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 17

18 Calling Methods DATA: cnt_1 TYPE REF TO counter. DATA number TYPE I VALUE 5. CREATE OBJECT cnt_1 TYPE counter. CALL METHOD cnt_1->set EXPORTING set_value = number. DO 3 TIMES. CALL METHOD cnt_1->increment. ENDDO. CALL METHOD cnt_1->get IMPORTING get_value = number. 1<COUNTER> NUMBER has the value 8 CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 18

19 Several Reference Variables DATA: cnt_1 TYPE REF TO counter, cnt_2 TYPE REF TO counter, cnt_3 TYPE REF TO counter. CNT_3 CNT_2 CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 19

20 Several Objects DATA: cnt_1 TYPE REF TO counter, cnt_2 TYPE REF TO counter, cnt_3 TYPE REF TO counter. CREATE OBJECT: cnt_1, cnt_2. 2<COUNTER> 1<COUNTER> CNT_3 CNT_2 CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 20

21 Assigning Reference Variables DATA: cnt_1 TYPE REF TO counter, cnt_2 TYPE REF TO counter, cnt_3 TYPE REF TO counter. CREATE OBJECT: cnt_1, cnt_2. MOVE cnt_2 TO cnt_3. 2<COUNTER> 1<COUNTER> CNT_3 CNT_2 CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 21

22 Deleting Reference Variables DATA: cnt_1 TYPE REF TO counter, cnt_2 TYPE REF TO counter, cnt_3 TYPE REF TO counter. CREATE OBJECT: cnt_1, cnt_2. MOVE cnt_2 TO cnt_3. CLEAR cnt_2. 2<COUNTER> 1<COUNTER> CNT_3 CNT_2 CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 22

23 Garbage Collection DATA: cnt_1 TYPE REF TO counter, cnt_2 TYPE REF TO counter, cnt_3 TYPE REF TO counter. CREATE OBJECT: cnt_1, cnt_2. MOVE cnt_2 TO cnt_3. CLEAR cnt_2. cnt_3 = cnt_1. 2<COUNTER> 1<COUNTER> CNT_3 CNT_2 CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 23

24 Garbage Collection DATA: cnt_1 TYPE REF TO counter, cnt_2 TYPE REF TO counter, cnt_3 TYPE REF TO counter. CREATE OBJECT: cnt_1, cnt_2. MOVE cnt_2 TO cnt_3. CLEAR cnt_2. cnt_3 = cnt_1. CLEAR cnt_3. 1<COUNTER> CNT_3 CNT_2 CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 24

25 New Objects DATA: cnt_1 TYPE REF TO counter, cnt_2 TYPE REF TO counter, cnt_3 TYPE REF TO counter. CREATE OBJECT: cnt_1, cnt_2. MOVE cnt_2 TO cnt_3. CLEAR cnt_2. cnt_3 = cnt_1. CLEAR cnt_3. 3<COUNTER> 2<COUNTER> 1<COUNTER> CREATE OBJECT: cnt_2, cnt_3. CNT_3 CNT_2 CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 25

26 Methods of Several Objects DATA: cnt_1 TYPE REF TO counter, cnt_2 TYPE REF TO counter, cnt_3 TYPE REF TO counter. CREATE OBJECT: cnt_1, cnt_2, cnt_3. CALL METHOD cnt_1->set EXPORTING set_value = 1. CALL METHOD cnt_2->set EXPORTING set_value = 10. CALL METHOD cnt_3->set EXPORTING set_value = 100. CNT_3 3<COUNTER> 2<COUNTER> 1<COUNTER> The value of COUNT is different in each object CNT_2 CNT_1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 26

27 Objects: Summary Declaring reference variables DATA: ref1 TYPE REF TO class, ref2 TYPE REF TO class. Creating objects CREATE OBJECT: ref1, ref2. Accessing attributes and methods x = ref1->attr + ref2->attr. CALL METHOD ref1->method EXPORTING SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 27

28 Classes in Detail Structure of classes Components of classes Accessing the components SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 28

29 Structure of Classes - Visibility Sections CLASS c1 DEFINITION. PUBLIC SECTION. DATA: a1 METHODS: m1 EVENTS: e1 PROTECTED SECTION. DATA: a2 METHODS: m2 EVENTS: e2 PRIVATE SECTION. DATA: a3 METHODS: m3 EVENTS: e3 CLASS c1 IMPLEMENTATION. METHOD m1. ENDMETHOD. METHOD m2. ENDMETHOD. METHOD m3. ENDMETHOD. a1, m1, e1 All users Public components Class c1 Private components a3, m3, e3 Method implementations Protected components a2, m2, e2, Subclasses of c1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 29

30 Components of Classes: Attributes CLASS DEFINITION. SECTION. DATA TYPE [READ-ONLY] CLASS-DATA TYPE [READ-ONLY] CONSTANTS TYPE VALUE DATA: Instance attributes CLASS-DATA:Static attributes CONSTANTS: Constants SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 30

31 Static Attributes and Instance Attributes CLASS c DEFINITION. PUBLIC SECTION. CLASS-DATA a1(10) TYPE C VALUE 'Static'. DATA a2(10) TYPE C VALUE 'Instance'. a1 CLASS 1<CLASS> DATA: cref TYPE REF TO c. a2 WRITE c=>a1. CREATE OBJECT cref TYPE c. CREF WRITE cref->a2. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 31

32 Components of Classes: Methods CLASS DEFINITION. SECTION. METHODS IMPORTING [VALUE] TYPE [OPTIONAL] EXPORTING [VALUE] TYPE CHANGING [VALUE] TYPE [OPTIONAL] RETURNING VALUE() TYPE EXCEPTIONS CLASS-METHODS CLASS IMPLEMENTATION. METHOD ENDMETHOD. METHODS: Instance methods CLASS-METHODS: Static methods SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 32

33 Constructors CLASS c DEFINITION. PUBLIC SECTION. METHODS CONSTRUCTOR [IMPORTING arg1 TYPE type ]. CLASS-METHODS CLASS_CONSTRUCTOR. CLASS c IMPLEMENTATION. METHOD CONSTRUCTOR. ENDMETHOD. METHOD CLASS_CONSTRUCTOR. ENDMETHOD. PROGRAM. DATA o1 TYPE REF TO c. CREATE OBJECT o1 EXPORTING arg1 = v1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 33

34 Accessing the components of classes Instance components ref >comp Instance attribute ref->attr Instance method: call method ref->meth Static components class=>comp Static attribute: class=>attr Static method: call method class=>meth Special references in methods Self reference: ME->comp Pseudo reference SUPER->comp n<class> ME SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 34

35 Inheritance Introduction Overview Single inheritance Redefining methods Example: Subclass of superclass counter SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 35

36 Inheritance: Introduction Definition of a class by inheriting the components from a superclass (Reuse) Specialization by adding own components and redefining methods in subclasses Polymorphism by accessing subclass objects CREF1 n<class3> class1 CREF2 class2 CREF3 class3 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 36

37 Inheritance - Overview Class OBJECT CLASS c1 DEFINITION INHERITING FROM Class c1 CLASS c1 IMPLEMENTATION. CLASS c2 DEFINITION INHERITING FROM c1. Class c2 CLASS c2 IMPLEMENTATION. Class SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 37

38 Single Inheritance OBJECT C1 C2 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 38

39 Redefining Methods CLASS DEFINITION INHERITING FROM SECTION. METHODS REDEFINITON CLASS IMPLEMENTATION. METHOD ENDMETHOD. Semantic rules Subclasses must behave just like their superclass for all users of inherited components A redefined method must observe the original semantics Inheritance should only be used to specialize SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 39

40 Inheritance and Constructors CLASS subclass DEFINITION INHERITING FROM superclass. PUBLIC SECTION. METHODS CONSTRUCTOR IMPORTING CLASS subclass IMPLEMENTATION. Access to static METHOD CONSTRUCTOR. attributes only CALL METHOD SUPER->CONSTRUCTOR EXPORTING Accress to instance ENDMETHOD. attributes also PROGRAM DATA o1 TYPE REF TO subclass. CREATE OBJECT o1 TYPE subclass EXPORTING SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 40

41 Subclass for Superclass Counter* CLASS CLASS counter_ten counter_ten DEFINITION DEFINITION INHERITING INHERITING FROM FROM counter. counter. PUBLIC PUBLIC SECTION. SECTION. METHODS METHODS increment increment REDEFINITION. REDEFINITION. DATA DATA count_ten. count_ten. CLASS CLASS counter_ten counter_ten IMPLEMENTATION. IMPLEMENTATION. METHOD METHOD increment. increment. DATA DATA modulo modulo TYPE TYPE I. I. CALL CALL METHOD METHOD super->increment. *Replace PRIVATE with: modulo modulo = count count mod mod PROTECTED IF IF modulo modulo = 0. PROTECTED SECTION. SECTION. 0. DATA count_ten count_ten = count_ten count_ten + 1. DATA count count TYPE TYPE I. I. 1. ENDIF. ENDIF. ENDMETHOD. ENDMETHOD. DATA: count TYPE REF TO counter. CREATE OBJECT count TYPE counter_ten. CALL METHOD count->set EXPORTING set_value = number. DO 10 TIMES. CALL METHOD count->increment. ENDDO. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 41

42 Interfaces Introduction Overview Definition Implementation Interface references Example: Interface for counter SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 42

43 Interfaces: Introduction Definition of an interface without implementation Classes can implement several interfaces Uniform access with interface references Polymorphism independent from inheritance n<class3> Interface iref_tab iref_line iref_line iref_line n<class2> n<class1> SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 43

44 Interfaces - Overview INTERFACE i1. DATA: a1 METHODS: m1 EVENTS: e1 ENDINTERFACE. CLASS c1 DEFINITION. PUBLIC SECTION. DATA a1 INTERFACES i1 PROTECTED SECTION. PRIVATE SECTION. Public components a1, i1~a1, i1~m1, class c1 Private components a2, m2, e2 Method implementations Protected components a3, m3, e3, CLASS c1 IMPLEMENTATION. METHOD i1~m1. ENDMETHOD. All users Subclasses of c1 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 44

45 Interfaces - Definition INTERFACE. DATA: TYPE [READ-ONLY] CLASS-DATA: TYPE [READ-ONLY] CONSTANTS: TYPE [VALUE ] METHODS: IMPORTING [VALUE] TYPE [OPTIONAL] EXPORTING [VALUE] TYPE CHANGING [VALUE] TYPE [OPTIONAL] RETURNING VALUE() TYPE EXCEPTIONS CLASS-METHODS: EVENTS: [EXPORTING VALUE() TYPE [OPTIONAL]]. CLASS-EVENTS: INTERFACES: ENDINTERFACE. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 45

46 Interfaces - Implementation CLASS DEFINITION. PUBLIC SECTION. INTERFACES: CLASS IMPLEMENTATION. METHOD ~ ENDMETHOD. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 46

47 Interface References INTERFACE i1. ENDINTERFACE. CLASS c1 DEFINITION. PUBLIC SECTION. DATA a1. INTERFACES i1. 1<C2> CLASS c2 DEFINITION. PUBLIC SECTION. INTERFACES i1. DATA cnt_c TYPE REF TO c1. DATA: cnt_1 TYPE REF TO i1, cnt_2 LIKE cnt_1. CREATE OBJECT: cnt_c TYPE c1, cnt_1 TYPE c2. MOVE cnt_c to cnt_2. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 47 CNT_1 CNT_C CNT_2 1<C1>

48 Interface for Object State - Implementation INTERFACE INTERFACE status. status. METHODS METHODS write. write. ENDINTERFACE. ENDINTERFACE. CLASS CLASS counter counter DEFINITION. DEFINITION. PUBLIC PUBLIC SECTION. SECTION. INTERFACES INTERFACES status. status. METHODS METHODS increment. increment. PRIVATE PRIVATE SECTION. SECTION. DATA DATA count count TYPE TYPE i. i. CLASS CLASS counter counter IMPLEMENTATION. IMPLEMENTATION. METHOD METHOD status~write. status~write. WRITE: WRITE: 'Count 'Count in in counter counter is', is', count. count. ENDMETHOD. ENDMETHOD. METHOD METHOD increment. increment. count count = count count ENDMETHOD. ENDMETHOD. CLASS CLASS bicycle bicycle DEFINITION. DEFINITION. CLASS PUBLIC PUBLIC SECTION. CLASS bicycle bicycle IMPLEMENTATION. IMPLEMENTATION. SECTION. METHOD INTERFACES INTERFACES status. METHOD status~write. status~write. status. WRITE: METHODS METHODS drive. WRITE: 'Speed 'Speed of of bicycle bicycle is', is', drive. speed. PRIVATE PRIVATE SECTION. speed. SECTION. ENDMETHOD. DATA DATA speed speed TYPE TYPE i. ENDMETHOD. i. METHOD METHOD drive. drive. speed speed = speed speed ENDMETHOD. ENDMETHOD. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 48

49 Interface for Object State - Use DATA: DATA: count count TYPE TYPE REF REF TO TO counter, counter, bike bike TYPE TYPE REF REF TO TO bicycle, bicycle, status status TYPE TYPE REF REF TO TO status. status. CREATE CREATE OBJECT: OBJECT: count, count, bike. bike. DO DO 5 TIMES. TIMES. CALL CALL METHOD: METHOD: count->increment, bike->drive. bike->drive. ENDDO. ENDDO. status status = count. count. CALL CALL METHOD METHOD status->write. status->write. status status = bike. bike. CALL CALL METHOD METHOD status->write. status->write. Counter status Bike speed SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 49

50 Events Introduction Overview Declaring and triggering events Event handler methods Handling events Example: Overflow in counter SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 50

51 Events - Introduction Events are components of classes Methods can raise the events of their class Handler methods can be triggered by events 2<HANDLER> 1<TRIGGER> 1<HANDLER> SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 51

52 Events - Overview CLASS c1 DEFINITION. PUBLIC SECTION. EVENTS e1 EXPORTING VALUE(p1) TYPE i. METHODS m1. PRIVATE SECTION. DATA a1 TYPE i. CLASS c2 DEFINITION. PUBLIC SECTION. METHODS m2 FOR EVENT e1 OF c1 IMPORTING p1. PRIVATE SECTION. DATA a2 TYPE i. CLASS c1 IMPLEMENTATION. METHOD m1. a1 = RAISE EVENT e1 EXPORTING p1 = a1. ENDMETHOD. CLASS C2 IMPLEMENTATION. METHOD m2. a2 = p1. ENDMETHOD. Event trigger Event handler SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 52

53 Declaring and Triggering Events CLASS DEFINITION. SECTION. METHODS EVENTS [EXPORTING VALUE() TYPE [OPTIONAL]]. CLASS-EVENTS CLASS IMPLEMENTATION. METHOD RAISE EVENT EXPORTING = ENDMETHOD. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 53

54 Event Handler Methods CLASS DEFINITION. SECTION. METHODS FOR EVENT OF [IMPORTING SENDER ]. CLASS IMPLEMENTATION. METHOD ENDMETHOD. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 54

55 Event Handling - Registration PROGRAM DATA: trigger TYPE REF TO trigger, handler_1 TYPE REF TO handler, handler_2 TYPE REF TO handler. CREATE OBJECT: trigger, handler_1, handler_2. SET HANDLER handler_1->handle_event handler_2->handle_event FOR trigger. CALL METHOD trigger->raise_event. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 55

56 Handling Events - References Ereignis 2<HANDLER> Methode Methode. 1<HANDLER> 1<TRIGGER> HANDLER_1 TRIGGER HANDLER_2 SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 56

57 Threshold in Counter - Trigger CLASS CLASS counter counter DEFINITION. DEFINITION. PUBLIC PUBLIC SECTION. SECTION. METHODS METHODS increment. increment. EVENTS EVENTS critical_value critical_value EXPORTING EXPORTING value(excess) value(excess) TYPE TYPE i. i. PRIVATE PRIVATE SECTION. SECTION. DATA: DATA: count count TYPE TYPE i, i, threshold threshold TYPE TYPE i VALUE VALUE CLASS CLASS counter counter IMPLEMENTATION. IMPLEMENTATION. METHOD METHOD increment. increment. DATA DATA diff diff TYPE TYPE i. i. count count = count count IF IF count count > threshold. threshold. diff diff = count count - threshold. threshold. RAISE RAISE EVENT EVENT critical_value critical_value EXPORTING EXPORTING excess excess = diff. diff. ENDIF. ENDIF. ENDMETHOD. ENDMETHOD. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 57

58 Threshold in Counter - Handling CLASS CLASS handler handler DEFINITION. DEFINITION. PUBLIC PUBLIC SECTION. SECTION. METHODS METHODS handle_excess handle_excess FOR FOR EVENT EVENT critical_value critical_value OF OF counter counter IMPORTING IMPORTING excess. excess. CLASS CLASS handler handler IMPLEMENTATION. IMPLEMENTATION. METHOD METHOD handle_excess. handle_excess. WRITE: WRITE: / Excess Excess is', is', excess. excess. ENDMETHOD. ENDMETHOD. DATA: DATA: cnt cnt TYPE TYPE REF REF TO TO counter, counter, react react TYPE TYPE REF REF TO TO handler. handler. CREATE CREATE OBJECT: OBJECT: cnt, cnt, react. react. SET SET HANDLER HANDLER react->handle_excess FOR FOR ALL ALL INSTANCES. INSTANCES. DO DO TIMES. TIMES. CALL CALL METHOD METHOD cnt->increment. cnt->increment. ENDDO. ENDDO. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 58

59 Using Global Classes Class pools Class Browser and Class Builder Class Builder Example: Using CL_GUI_PICTURE SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 59

60 Class Pools CLASS-POOL TYPES TYPES CLASS CLASS Visibility INTERFACE INTERFACE ENDINTERFACE. ENDINTERFACE. CLASS CLASS DEFINITION DEFINITION PUBLIC. PUBLIC. CLASS CLASS IMPLEMENTATION. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 60

61 Class Library and Class Browser SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 61

62 Class Builder SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 62

63 Using a Global Class CLASS CLASS reaction reaction DEFINITION. DEFINITION. PUBLIC PUBLIC SECTION. SECTION. METHODS METHODS on_single_click on_single_click FOR FOR EVENT EVENT picture_click picture_click OF OF cl_gui_picture. cl_gui_picture. DATA: DATA: container1 container1 TYPE TYPE REF REF TO TO cl_gui_custom_container, container2 container2 LIKE LIKE container1, container1, pict1 pict1 TYPE TYPE REF REF TO TO cl_gui_picture, cl_gui_picture, pict2 pict2 LIKE LIKE pict1, pict1, react react TYPE TYPE REF REF TO TO reaction, reaction, CREATE CREATE OBJECT: OBJECT: container1 container1 EXPORTING EXPORTING container_name container_name = 'PICTURE1', 'PICTURE1', container2 container2 EXPORTING EXPORTING container_name container_name = 'PICTURE2', 'PICTURE2', pict1 pict1 EXPORTING EXPORTING parent parent = container1, container1, pict2 pict2 EXPORTING EXPORTING parent parent = container2, container2, react. react. SET SET HANDLER HANDLER react->on_single_click FOR FOR pict1. pict1. CALL CALL METHOD METHOD pict1->load_picture_from_url CLASS CLASS reaction reaction IMPLEMENTATION. IMPLEMENTATION. METHOD METHOD on_single_click. CALL CALL METHOD METHOD pict2->load_picture_from_url ENDMETHOD. ENDMETHOD. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 63

64 Example of CL_GUI_PICTURE SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 64

65 Mouse Click SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 65

66 After Mouse Click SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 66

67 Further Information Transaction ABAPDOCU Keyword documentation SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 67

68 Further Information Transaction ABAPDOCU SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 68

69 Further Information Keyword Documentation SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 69

70 Exercises 1. Defining classes 2. Creating objects 3. Deriving classes using inheritance 4. Using interfaces 5. Triggering and handling events SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 70

71 Exercises - Scenario Class "Vehicle" with attribute for speed, and a method for changing it Interface Status With methods for displaying attributes Class "Helicopter" Can handle events from ship Class "Truck" with its own maximum speed and attribute output SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 71 Class "Ship" with its own maximum speed and attribute output, a name, and an event

72 Exercise 1 - Classes Copy the template ABAP_OBJECTS_ENJOY_0 into an own program. Define a local class VEHICLE in the designated area in front of the predefined class MAIN. Class VEHICLE should have the protected instance attributes SPEED and MAX_SPEED for its speed and maximum speed, and the public methods SPEED_UP, STOP, and WRITE. SPEED_UP should have an IMPORTING parameter STEP. The method should increase the speed by STEP, but not allow it to exceed the maximum speed. STOP should reset the speed to zero. WRITE should display a list line containing the speed and the maximum speed. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 72

73 Exercise 2 - Objects Continuing the program from exercise 1, create objects from the class VEHICLE. Program the respective coding in the predefined method START of class MAIN. Define a reference variable VEHICLE with type VEHICLE, and an internal table VEHICLE_TAB, whose line type is also a reference variable to this class. In a DO loop, create a number of instances of the class VEHICLE and insert them into the internal table. In a LOOP construction, call the methods SPEED_UP and WRITE once for each entry in the internal table. When you call SPEED_UP, pass the value SY-TABIX * 10 to the parameter STEP. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 73

74 Exercise 3 - Inheritance Change your program from exercise 2 to define classes TRUCK and SHIP as direct subclasses of VEHICLE. The class TRUCK should have an instance constructor and redefine the method WRITE. The class SHIP should have an IMPORTING parameter NAME, a new public attribute NAME, and should also redefine the method WRITE. The instance constructor of each class should change the maximum speed. The instance constructor of SHIP should set the attribute NAME to the actual parameter that you imported. The WRITE method should show the class from which the display comes. For SHIP, use the NAME attribute. Declare extra reference variables TRUCK and SHIP for the new classes. You can delete the code that creates objects for VEHICLE. Instead, create one instance of each of your new classes and place the corresponding reference into VEHICLE_TAB. Call the method SPEED_UP for both classes using the correct subclass reference, and WRITE using a superclass reference. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 74

75 Exercise 4 - Interfaces Change your program from exercise 3 so that the method WRITE is contained in an interface STATUS. The class VEHICLE should implement the interface instead of its own WRITE method. The name must be changed accordingly in each implementation (including the subclasses), but the function remains the same. Replace the reference variables VEHICLE and the table VEHICLE_TAB with the interface reference STATUS and internal table STATUS_TAB. Use these references to display the status of the objects. Create a new class HELICOPTER that also implements STATUS. Declare an alias WRITE in that class for the interface method. The interface method in HELICOPTER should display a different line from that displayed in VEHICLE. Declare a reference variable HELI for the class HELICOPTER, create a corresponding object, and insert the reference variable into the table STATUS_TAB. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 75

76 Exercise 5 - Events Change your program from exercise 4 to include an event DAMAGED for the class SHIP. Redefine the method SPEED_UP in the class SHIP. When the maximum speed is exceeded, SPEED_UP should set the maximum speed to zero and trigger the event DAMAGED. Add a new method RECEIVE to the class HELICOPTER to allow it to handle the event DAMAGED. Import the implicit parameter SENDER. RECEIVE should use the SENDER parameter to display the name of the ship that triggered the event. Register the handler method of the object to which HELI is pointing as a handler for objects from the class SHIP. Increase the speed of the object from the class SHIP until it exceeds the maximum speed and triggers the event. SAP AG 1999 ABAP Objects - Introduction (Horst Keller) / 76

Not Yet Using ABAP Objects? Eight Reasons Why Every ABAP Developer Should Give It a Second Look

Not Yet Using ABAP Objects? Eight Reasons Why Every ABAP Developer Should Give It a Second Look Not Yet Using ABAP Objects? Eight Reasons Why Every ABAP Developer Should Give It a Second Look Not Yet Using ABAP Objects? Eight Reasons Why Every ABAP Developer Should Give It a Second Look Horst Keller

More information

Official ABAP Programming Guidelines

Official ABAP Programming Guidelines Horst Keller, Wolf Hagen Thümmel Official ABAP Programming Guidelines Bonn Boston 290_Book_TIGHT.indb 3 9/2/09 3:27:36 PM Contents at a Glance 1 Introduction... 17 2 General Basic Rules... 23 3 ABAP-Specific

More information

R/3 System Object-Oriented Concepts of ABAP

R/3 System Object-Oriented Concepts of ABAP R/3 System Object-Oriented Concepts of ABAP Copyright 1997 SAP AG. All rights reserved. No part of this brochure may be reproduced or transmitted in any form or for any purpose without the express permission

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

Preface Introduction... 23

Preface Introduction... 23 Preface... 19 1 Introduction... 23 1.1 Releases Used... 23 1.2 New Features in Releases 7.02 and 7.2... 25 1.2.1 New Features in ABAP... 25 1.2.2 New Features in Tools... 28 1.3 Syntax Conventions in The

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

Function Modules Objective The following section is intended to explain: What function modules are Components of function modules

Function Modules Objective The following section is intended to explain: What function modules are Components of function modules Function Modules Objective The following section is intended to explain: What function modules are Components of function modules Testing and releasing of function modules Function Modules Function modules

More information

JAVA MOCK TEST JAVA MOCK TEST II

JAVA MOCK TEST JAVA MOCK TEST II http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET VB.NET Module 1: Getting Started This module introduces Visual Basic.NET and explains how it fits into the.net platform. It explains how to use the programming tools in Microsoft Visual Studio.NET and

More information

Arrays Classes & Methods, Inheritance

Arrays Classes & Methods, Inheritance Course Name: Advanced Java Lecture 4 Topics to be covered Arrays Classes & Methods, Inheritance INTRODUCTION TO ARRAYS The following variable declarations each allocate enough storage to hold one value

More information

C_TAW12_740

C_TAW12_740 C_TAW12_740 Passing Score: 800 Time Limit: 0 min Exam A QUESTION 1 You want to add a field ZZPRICE to the SAP standard transparent table EKKO. Which of the following actions results in an enhancement of

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

More information

Java: introduction to object-oriented features

Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L Inheritance Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 9.4 1 Inheritance Inheritance allows a software developer to derive

More information

Object Oriented Programming. Java-Lecture 11 Polymorphism

Object Oriented Programming. Java-Lecture 11 Polymorphism Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class

More information

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes Inheritance Inheritance is the mechanism of deriving new class from old one, old class is knows as superclass and new class is known as subclass. The subclass inherits all of its instances variables and

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract Classes

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

SDN Community Contribution

SDN Community Contribution SDN Community Contribution (This is not an official SAP document.) Disclaimer & Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces

More information

Inheritance -- Introduction

Inheritance -- Introduction Inheritance -- Introduction Another fundamental object-oriented technique is called inheritance, which, when used correctly, supports reuse and enhances software designs Chapter 8 focuses on: the concept

More information

Chapter 8: Class and Method Design

Chapter 8: Class and Method Design Chapter 8: Class and Method Design Objectives Become familiar with coupling, cohesion, and connascence. Be able to specify, restructure, and optimize object designs. Be able to identify the reuse of predefined

More information

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

IT101. Inheritance, Encapsulation, Polymorphism and Constructors IT101 Inheritance, Encapsulation, Polymorphism and Constructors OOP Advantages and Concepts What are OOP s claims to fame? Better suited for team development Facilitates utilizing and creating reusable

More information

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing

More information

Subtyping (Dynamic Polymorphism)

Subtyping (Dynamic Polymorphism) Fall 2018 Subtyping (Dynamic Polymorphism) Yu Zhang Course web site: http://staff.ustc.edu.cn/~yuzhang/tpl References PFPL - Chapter 24 Structural Subtyping - Chapter 27 Inheritance TAPL (pdf) - Chapter

More information

Object Oriented Paradigm

Object Oriented Paradigm Object Oriented Paradigm History Simula 67 A Simulation Language 1967 (Algol 60 based) Smalltalk OO Language 1972 (1 st version) 1980 (standard) Background Ideas Record + code OBJECT (attributes + methods)

More information

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze

More information

Programming 1 Semester 1, 2014 Assignment 3

Programming 1 Semester 1, 2014 Assignment 3 Programming 1 Semester 1, 2014 Assignment 3 Authors: Daryl D Souza, Craig Hamilton Total raw marks: 150 Assignment weight: 20% NOTE: This assignment is to be undertaken individually no group work is permitted.

More information

Lecture 10 OOP and VB.Net

Lecture 10 OOP and VB.Net Lecture 10 OOP and VB.Net Pillars of OOP Objects and Classes Encapsulation Inheritance Polymorphism Abstraction Classes A class is a template for an object. An object will have attributes and properties.

More information

Object-Oriented Design (OOD) and C++

Object-Oriented Design (OOD) and C++ Chapter 2 Object-Oriented Design (OOD) and C++ At a Glance Instructor s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Questions Projects to Assign

More information

Programming Exercise 14: Inheritance and Polymorphism

Programming Exercise 14: Inheritance and Polymorphism Programming Exercise 14: Inheritance and Polymorphism Purpose: Gain experience in extending a base class and overriding some of its methods. Background readings from textbook: Liang, Sections 11.1-11.5.

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered

More information

QUESTIONS FOR AVERAGE BLOOMERS

QUESTIONS FOR AVERAGE BLOOMERS MANTHLY TEST JULY 2017 QUESTIONS FOR AVERAGE BLOOMERS 1. How many types of polymorphism? Ans- 1.Static Polymorphism (compile time polymorphism/ Method overloading) 2.Dynamic Polymorphism (run time polymorphism/

More information

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3 Course Code: GK1965 Overview Java 8 Essentials for OO Developers is a three-day, fast-paced, quick start to Java 8 training

More information

Inheritance. OOP: Inheritance 1

Inheritance. OOP: Inheritance 1 Inheritance Reuse Extension and intension Class specialization and class extension Inheritance The protected keyword revisited Inheritance and methods Method redefinition An widely used inheritance example

More information

Chapter 10 Classes Continued. Fundamentals of Java

Chapter 10 Classes Continued. Fundamentals of Java Chapter 10 Classes Continued Objectives Know when it is appropriate to include class (static) variables and methods in a class. Understand the role of Java interfaces in a software system and define an

More information

Module 10 Inheritance, Virtual Functions, and Polymorphism

Module 10 Inheritance, Virtual Functions, and Polymorphism Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:

More information

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1 OBJECT ORIENTED SIMULATION LANGUAGE OOSimL Reference Manual - Part 1 Technical Report TR-CSIS-OOPsimL-1 José M. Garrido Department of Computer Science Updated November 2014 College of Computing and Software

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET

2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET 2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET Introduction Elements of this syllabus are subject to change. This five-day instructor-led course provides students with the knowledge

More information

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

(800) Toll Free (804) Fax   Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days Course Description This course introduces the Java programming language and how to develop Java applications using Eclipse 3.0. Students learn the syntax of the Java programming language, object-oriented

More information

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008 Overview Lecture 7: Inheritance and GUIs Written by: Daniel Dalevi Inheritance Subclasses and superclasses Java keywords Interfaces and inheritance The JComponent class Casting The cosmic superclass Object

More information

WUS 581:WEBCLIENT UI FRAMEWORK : UI COMPONENT ENHANCEMENTS SCENARIOS. 1. UI Component Architecture

WUS 581:WEBCLIENT UI FRAMEWORK : UI COMPONENT ENHANCEMENTS SCENARIOS. 1. UI Component Architecture CRM TECHNICAL DEMO With OOPS @ BANDIS TECHNOLOGY Date : 17/11/2012 Time : 8 AM Contact : 040-64608866, 09030098866, 8790898802 Email : BANDIS.TECHNOLOGY@GMAIL.COM Faculty : NAIK (SAP CRM, EP Certified

More information

Student Performance Q&A:

Student Performance Q&A: Student Performance Q&A: 2004 AP Computer Science A Free-Response Questions The following comments on the 2004 free-response questions for AP Computer Science A were written by the Chief Reader, Chris

More information

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

More information

And Even More and More C++ Fundamentals of Computer Science

And Even More and More C++ Fundamentals of Computer Science And Even More and More C++ Fundamentals of Computer Science Outline C++ Classes Special Members Friendship Classes are an expanded version of data structures (structs) Like structs, the hold data members

More information

CS 403/503 Exam 4 Spring 2015 Solution

CS 403/503 Exam 4 Spring 2015 Solution CS 403/503 Exam 4 Spring 2015 Solution Each problem initially scored out of 10 points possible. CS 403 Best 5 answers doubled. (5*20 + 2*10 = 120 possible) CS 503 Best 4 answers doubled. (4*20 + 3*10 =

More information

Computer Science 210: Data Structures

Computer Science 210: Data Structures Computer Science 210: Data Structures Summary Today writing a Java program guidelines on clear code object-oriented design inheritance polymorphism this exceptions interfaces READING: GT chapter 2 Object-Oriented

More information

SAP Container HELP.BCCIDOCK. Release 4.6C

SAP Container HELP.BCCIDOCK. Release 4.6C HELP.BCCIDOCK Release 4.6C SAP AG Copyright Copyright 2001 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission

More information

Object Oriented Software Development CIS Today: Object Oriented Analysis

Object Oriented Software Development CIS Today: Object Oriented Analysis Object Oriented Software Development CIS 50-3 Marc Conrad D104 (Park Square Building) Marc.Conrad@luton.ac.uk Today: Object Oriented Analysis The most single important ability in object oriented analysis

More information

C++ Inheritance and Encapsulation

C++ Inheritance and Encapsulation C++ Inheritance and Encapsulation Private and Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance 1 Private Members Private members

More information

Chapter 7. Inheritance

Chapter 7. Inheritance Chapter 7 Inheritance Introduction to Inheritance Inheritance is one of the main techniques of objectoriented programming (OOP) Using this technique, a very general form of a class is first defined and

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Inheritance. Transitivity

Inheritance. Transitivity Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated

More information

M Introduction to Visual Basic.NET Programming with Microsoft.NET 5 Day Course

M Introduction to Visual Basic.NET Programming with Microsoft.NET 5 Day Course Module 1: Getting Started This module introduces Visual Basic.NET and explains how it fits into the.net platform. It explains how to use the programming tools in Microsoft Visual Studio.NET and provides

More information

ENCAPSULATION AND POLYMORPHISM

ENCAPSULATION AND POLYMORPHISM MODULE 3 ENCAPSULATION AND POLYMORPHISM Objectives > After completing this lesson, you should be able to do the following: Use encapsulation in Java class design Model business problems using Java classes

More information

C_TAW12_740

C_TAW12_740 C_TAW12_740 Passing Score: 800 Time Limit: 4 min Exam A QUESTION 1 Which of the foldynpro application to transaction database data to the user interface? A. Interface controller B. Supply function C. Inbound

More information

Computer Science II (20073) Week 1: Review and Inheritance

Computer Science II (20073) Week 1: Review and Inheritance Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system

More information

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring

More information

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance? CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 5: Inheritance & Polymorphism Lecture Contents 2 What is Inheritance? Super-class & sub class Protected members Creating subclasses

More information

BC401. ABAP Objects COURSE OUTLINE. Course Version: 18 Course Duration:

BC401. ABAP Objects COURSE OUTLINE. Course Version: 18 Course Duration: BC401 ABAP Objects. COURSE OUTLINE Course Version: 18 Course Duration: SAP Copyrights and Trademarks 2018 SAP SE or an SAP affiliate company. All rights reserved. No part of this publication may be reproduced

More information

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java

More information

Module 7. Advanced Class Features

Module 7. Advanced Class Features Module 7 Advanced Class Features Java Programming Language Objectives Describe static variables, methods, and initializers Describe final classes, methods, and variables Explain how and when to use abstract

More information

SAP Policy Management 5.3 SP03

SAP Policy Management 5.3 SP03 How-To Guide SAP Policy Management Document Version: 1.3 2016-11-30 Guide for Implementing Business Transactions Typographic Conventions Type Style Example Description Words or characters quoted from the

More information

VIRTUAL FUNCTIONS Chapter 10

VIRTUAL FUNCTIONS Chapter 10 1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions

More information

Using Inheriting and Overloading concept in creating reusable universal test method library

Using Inheriting and Overloading concept in creating reusable universal test method library Using Inheriting and Overloading concept in creating reusable universal test method library ZhiJun Xue, Zhi-jun.xue@verigy.com Zane Jiang Zane.jiang@verigy.com Introduction Test method is a critical software

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Inheritance Three main programming mechanisms that constitute object-oriented programming (OOP) Encapsulation

More information

Function Module to Create Logo

Function Module to Create Logo Applies To: SAP 4.0-4.7 Summary Utilities Function Module to create a Logo on a Custom Control Container. By: Arpit Nigam Company and Title: Hexaware Tech. Ltd., SAP Consultant Date: 26 Sep 2005 Table

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Object-Oriented Programming (OOP) Fundamental Principles of OOP Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is

More information

More C++ : Vectors, Classes, Inheritance, Templates

More C++ : Vectors, Classes, Inheritance, Templates Vectors More C++ : Vectors,, Inheritance, Templates vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes defined differently can be resized without explicit

More information

Tutorial 7. If it compiles, what does it print? Inheritance 1. Inheritance 2

Tutorial 7. If it compiles, what does it print? Inheritance 1. Inheritance 2 Tutorial 7 If it compiles, what does it print? Here are some exercises to practice inheritance concepts, specifically, overriding, overloading, abstract classes, constructor chaining and polymorphism.

More information

Basics of Object Oriented Programming. Visit for more.

Basics of Object Oriented Programming. Visit   for more. Chapter 4: Basics of Object Oriented Programming Informatics Practices Class XII (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra,

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 5: Inheritance & Polymorphism Lecture Contents 2 What is Inheritance? Super-class & sub class Protected members Creating subclasses

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

How to create an automatic activity for GPA With Solution Manager 7.2 SP3

How to create an automatic activity for GPA With Solution Manager 7.2 SP3 How to create an automatic activity for GPA With Solution Manager 7.2 SP3 Introduction: With the Guided Procedure Authoring in SAP Solution Manager 7.2 you have the possibility to create their own guided

More information

EMBEDDED SYSTEMS PROGRAMMING OO Basics

EMBEDDED SYSTEMS PROGRAMMING OO Basics EMBEDDED SYSTEMS PROGRAMMING 2014-15 OO Basics CLASS, METHOD, OBJECT... Class: abstract description of a concept Object: concrete realization of a concept. An object is an instance of a class Members Method:

More information

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com More C++ : Vectors, Classes, Inheritance, Templates with content from cplusplus.com, codeguru.com 2 Vectors vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

More information

Slider (2) Dynpro. Screenshot

Slider (2) Dynpro. Screenshot Slider (2) Noch eine Variante des Sliders. Diesmal mithilfe einer Windows-OCX-Bibliothek. Der Slider hat keine Beschriftung, hat aber den Vorteil, dass auf eine Wertänderung sofort reagiert werden kann.

More information

Polymorphism. Object Orientated Programming in Java. Benjamin Kenwright

Polymorphism. Object Orientated Programming in Java. Benjamin Kenwright Polymorphism Object Orientated Programming in Java Benjamin Kenwright Quizzes/Labs Every single person should have done Quiz 00 Introduction Quiz 01 - Java Basics Every single person should have at least

More information

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence.

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence. Constructor in Java 1. What are CONSTRUCTORs? Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs

More information

Object Orientated Programming Details COMP360

Object Orientated Programming Details COMP360 Object Orientated Programming Details COMP360 The ancestor of every action is a thought. Ralph Waldo Emerson Three Pillars of OO Programming Inheritance Encapsulation Polymorphism Inheritance Inheritance

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Ray John Pamillo 1/27/2016 1 Nokia Solutions and Networks 2014 Outline: Brief History of OOP Why use OOP? OOP vs Procedural Programming What is OOP? Objects and Classes 4 Pillars

More information

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed CREATED BY: Muhammad Bilal Arslan Ahmad Shaad JAVA Chapter No 5 Instructor: Muhammad Naveed Muhammad Bilal Arslan Ahmad Shaad Chapter No 5 Object Oriented Programming Q: Explain subclass and inheritance?

More information

Java Programming Lecture 7

Java Programming Lecture 7 Java Programming Lecture 7 Alice E. Fischer Feb 16, 2015 Java Programming - L7... 1/16 Class Derivation Interfaces Examples Java Programming - L7... 2/16 Purpose of Derivation Class derivation is used

More information

Chapter 11 Object and Object- Relational Databases

Chapter 11 Object and Object- Relational Databases Chapter 11 Object and Object- Relational Databases Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Outline Overview of Object Database Concepts Object-Relational

More information

Introduction to Computer Science II CS S-10 Inheritance

Introduction to Computer Science II CS S-10 Inheritance Introduction to Computer Science II CS112-2012S-10 Inheritance David Galles Department of Computer Science University of San Francisco 10-0: Classes Want to create a bunch of classes for a real estate

More information

U:\Book\Book_09.doc Multilanguage Object Programming

U:\Book\Book_09.doc Multilanguage Object Programming 1 Book 9 Multilanguage Object Programming U:\Book\Book_09.doc Multilanguage Object Programming 5 What to Read in This Part Multilanguage Object Programming... 1 1 Programming Objects In Java, VB and ABAP...

More information

Non-instantiable Classes

Non-instantiable Classes Instantiable Classes It is not acceptable to write a program using just the main method. Why? Programs become too large and unmanageable It is not acceptable to write programs using just predefined classes.

More information

Programming overview

Programming overview Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in

More information

Polymorphism 2/12/2018. Which statement is correct about overriding private methods in the super class?

Polymorphism 2/12/2018. Which statement is correct about overriding private methods in the super class? Which statement is correct about overriding private methods in the super class? Peer Instruction Polymorphism Please select the single correct answer. A. Any derived class can override private methods

More information

Superclasses / subclasses Inheritance in Java Overriding methods Abstract classes and methods Final classes and methods

Superclasses / subclasses Inheritance in Java Overriding methods Abstract classes and methods Final classes and methods Lecture 12 Summary Inheritance Superclasses / subclasses Inheritance in Java Overriding methods Abstract classes and methods Final classes and methods Multiplicity 1 By the end of this lecture, you will

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

Casting -Allows a narrowing assignment by asking the Java compiler to "trust us"

Casting -Allows a narrowing assignment by asking the Java compiler to trust us Primitives Integral types: int, short, long, char, byte Floating point types: double, float Boolean types: boolean -passed by value (copied when returned or passed as actual parameters) Arithmetic Operators:

More information

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods. Inheritance Inheritance is the act of deriving a new class from an existing one. Inheritance allows us to extend the functionality of the object. The new class automatically contains some or all methods

More information