Escolar Documentos
Profissional Documentos
Cultura Documentos
of innovation
Principles
Objects
Classes
Attributes
Methods
Instantiation, Garbage Collector
Working with Objects
Further Principles
Global network
of innovation
Principles : Overview-1
Objects
Classes
Attributes
Methods
Instantiation, Garbage Collector
Working with Objects
Further Principles
Global network
of innovation
Object-1
Example: airplane
Attributes
Plane ID: ID0057231
Weight: 30,000 kg
Length: 70 m
Attributes
Name: LH Berlin
Methods
land
fly
Methods
Events
Private access
Encapsulation
As a rule, attributes
Events
landed
Public access
Interface
As
a rule,methods, events
Global network
of innovation
Object-2
What characterizes an object?
Identity
Object
Instance
Global network
of innovation
Example of Objects
Eberwein
Plane ticket
1
.
Mr
Departure: Berlin: 06:10 p.m.
Name:
Name: Mr Gore
Departure: Mumbai: 06:10 p.m.
Mllerschn
2
2Plane ticket
Mr.
Name:
Name:Mr Dongare
Departure: Pune : 9:15 p.m.
Global network
of innovation
Classification
Plane
Plane ticket
Mllerschn
Mllerschn
Plane
ticket
Plane ticket.. 22
Mr
Mr
Departure:
Departure: Munich:
Munich: 11:25
11:25 a.m.
a.m.
Name:
Name:
Eberwein
Eberwein
Plane
Plane ticket
ticket.. 11
Mr
Mr
Departure:
Departure: Berlin:
Berlin: 06:10
06:10 p.m.
p.m.
Name:
Name:
Global network
of innovation
Principles : Overview-2
Objects
Classes
Attributes
Methods
Instantiation, Garbage Collector
Working with Objects
Further Principles
Global network
of innovation
Definition part
The class components (for
example, attributes and methods)
are defined in this part.
Implementation part
This part only contains the method
implementations.
Global network
of innovation
Data
Methods
Executable coding
Global network
of innovation
Principles : Overview-3
Objects
Classes
Attributes
Methods
Instantiation, Garbage Collector
Working with Objects
Further Principles
10
Global network
of innovation
Attributes
Attribute types can have any kind of data type:
Elementary types:
C, I, P, STRING
lcl_airplane
name: LH
weight: 30 000
Berlin
kg
tank:
lcl_tank
11
Global network
of innovation
Attributes : Syntax
CLASS
CLASS <
<classname
classname>
> DEFINITION.
DEFINITION.
...
...
TYPES:
TYPES: <
< normale
normale Typdefinition
Typdefinition >.
>.
CONSTANTS:
CONSTANTS: constant
constant TYPE
TYPE <type>
<type> VALUE
VALUE <value>.
<value>.
DATA:
DATA: variable1
variable1
variable2
variable2
variable3
variable3
variable4
variable4
variable5
variable5
variable6
variable6
variable7
variable7
TYPE
TYPE <type>,
<type>,
TYPE
TYPE <
<ddic
ddic_type>,
_type>,
LIKE
LIKE variable1,
variable1,
TYPE
TYPE <type>
<type> VALUE
VALUE <value>,
<value>,
TYPE
TYPE <type>
<type> READ-ONLY
READ-ONLY,
,
TYPE
TYPE REF
REF TO
TO <
<classname
classname>,
>,
TYPE
TYPE REF
REF TO
TO <interface>.
<interface>.
CLASS-DATA:
CLASS-DATA: ...
...
ENDCLASS.
ENDCLASS.
12
Global network
of innovation
Attributes : Visibility
CLASS
CLASS lcl
lcl_airplane
_airplane DEFINITION.
DEFINITION.
PUBLIC
PUBLIC SECTION.
SECTION.
DATA
DATA:
: name
name TYPE
TYPE string.
string.
Public attributes
Direct access
PRIVATE
PRIVATE SECTION.
SECTION.
DATA:
DATA: weight
weight TYPE
TYPE saplane
saplane-weight.
-weight.
ENDCLASS.
ENDCLASS.
CLASS
CLASS lcl
lcl_airplane
_airplane DEFINITION.
DEFINITION.
Private attributes
PUBLIC
PUBLIC SECTION.
SECTION.
...
...
PRIVATE
PRIVATE SECTION.
SECTION.
DATA
:
weight
TYPE
DATA : weight
TYPE saplane
saplane-weight,
-weight,
better
name
TYPE
string.
name TYPE string.
No direct access
from outside the class
ENDCLASS.
ENDCLASS.
13
Global network
of innovation
Statement: DATA
Static attributes
CLASS-DATA : count TYPE I.
Statement: CLASS-DATA
ENDCLASS.
14
Global network
of innovation
count:
2
name: LH Berlin
weight: 30,000 kg
name: AA Boston
weight: 45,000 kg
Main
memory
Static attributes for class LCL_AIRPLANE
15
Global network
of innovation
Principles : Overview-4
Objects
Classes
Attributes
Methods
Instantiation, Garbage Collector
Working with Objects
Further Principles
16
Global network
of innovation
Methods
Contain coding
Have an interface
lcl _airplane
...
fly
land
17
Global network
of innovation
Methods : Syntax
CLASS < classname > DEFINITION .
...
METHODS : <method_name>
[ IMPORTING < im _var > TYPE <type>
EXPORTING <ex_ var > TYPE <type>
CHANGING
< ch _var > TYPE <type>
RETURNING VALUE( <re_ var > ) TYPE <type>
EXCEPTIONS <exception> ].
ENDCLASS.
18
Global network
of innovation
Methods : Visibility
Public methods
Private methods
19
Global network
of innovation
Static methods
20
Global network
of innovation
21
Global network
of innovation
lcl _airplane
- name: string
- count: i
Methods
+ public components
- private components
+ get_count(): i
- set_count( im_count: i)
CLASS lcl _airplane DEFINITION.
PUBLIC SECTION.
METHODS:
set_name IMPORTING im _name TYPE string.
CLASS-METHODS: get_count RETURNING VALUE(re_count) TYPE I.
PRIVATE SECTION.
DATA:
name TYPE string.
CLASS-DATA: count TYPE I.
METHODS: set_count IMPORTING im _count TYPE i.
ENDCLASS.
22
Global network
of innovation
Principles : Overview-5
Objects
Classes
Attributes
Methods
Instantiation, Garbage Collector
Working with Objects
Further Principles
23
Global network
of innovation
Creating Objects
Objects can only be created and addressed using
reference variables
lcl _airplane
name
weight
...
CREATE OBJECT
name: LH Berlin
weight: 30,000 kg
24
Global network
of innovation
Referance Variables
CLASS lcl _airplane DEFINITION.
PUBLIC SECTION.
...
PRIVATE SECTION.
...
ENDCLASS.
airplane1
airplane2
Main memory
25
Global network
of innovation
airplane1
airplane2
name:
weight: 0
name:
weight: 0
Main memory
26
Global network
of innovation
Assigning References
...
DATA: airplane1 TYPE REF TO
airplane2 TYPE REF TO
lcl _airplane,
lcl _airplane.
airplane1
airplane2
name:
weight: 0
name:
weight: 0
Main memory
27
Global network
of innovation
Garbage Collector
...
DATA: airplane1 TYPE REF TO lcl _airplane,
airplane2 TYPE REF TO lcl _airplane.
CREATE OBJECT airplane1 EXPORTING ... .
CREATE OBJECT airplane2 EXPORTING ... .
airplane1 = airplane2.
airplane1
airplane2
name: LH B
weight: 30,000 kg
name: AA Bost
weight: 45,000 kg
Main memory
28
Global network
of innovation
All independent references in the global main memory are checked. The
references point to active objects, which are marked internally.
Objects that are not marked are deleted from the main memory.
Main memory
29
Global network
of innovation
Principles : Overview-6
Objects
Classes
Attributes
Methods
Instantiation, Garbage Collector
Working with Objects
Further Principles
30
Global network
of innovation
References : Comparison
DATA: airplane1 TYPE REF TO
airplane2 TYPE REF TO
lcl _airplane,
lcl _airplane.
airplane1
airplane2
not equal to
n: LH Berlin
w: 30,000 kg
n: LH Berlin
w: 30,000 kg
Main memory
31
Global network
of innovation
Buffering References -1
DATA: airplane
airplane_table
airplane
airplane_table
Main memory
airplane
airplane_table
Main memory
32
Global network
of innovation
Buffering References -2
LOOP AT TO airplane_table INTO airplane.
*
ENDLOOP.
airplane
airplane_table
2
Main memory
33
Global network
of innovation
lcl_airplane
name: LH Berlin
weight: 30,000 kg
left_wing:
right_wing:
lcl_wings
orientat .: left
length: 15 m
orientat .: right
length: 15 m
34
Global network
of innovation
name: LH Berlin
35
Global network
of innovation
Calling Methods
Run
Data
O1
Do_it
Data
O2
36
Global network
of innovation
Static methods:
37
Global network
of innovation
Functional Methods
When defining:
RETURNING parameters
Only IMPORTING parameters and exceptions are also possible
When calling:
RECEIVING parameters, or ...
... Various forms of direct call possible:
38
Global network
of innovation
* Instantiation omitted
* CALL METHOD plane1->get_count RECEIVING re_count = count_planes.
count_planes = lcl _airplane=>get_count( ).
fuel_consumption =
plane1->estimated_fuel_consumption( 1000 )
+ plane2->estimated_fuel_consumption( im _distance = 1500 ).
39
Global network
of innovation
Constructor
Special method for creating
objects with defined initial
state
Only has IMPORTING
parameters and
EXCEPTIONS
Exactly one constructor is
defined per class (explicitly
or implicitly)
lcl _airplane
name
weight
count
constructor
CREATE OBJECT
name: LH Berlin
weight: 30,000 kg
40
Global network
of innovation
Constructor : Example
CLASS lcl _airplane DEFINITION.
PUBLIC SECTION.
METHODS CONSTRUCTOR IMPORTING
im _name
TYPE string
im _weight TYPE I.
PRIVATE SECTION.
DATA: name TYPE string, weight TYPE I.
CLASS-DATA count TYPE I.
ENDCLASS.
CLASS lcl _airplane IMPLEMENTATION.
METHOD CONSTRUCTOR.
name = im _name.
weight = im _weight.
count = count + 1.
ENDMETHOD.
ENDCLASS.
DATA airplane TYPE REF TO lcl _airplane.
name: LH Berlin
...
weight: 30,000 kg
CREATE OBJECT airplane
EXPORTING im _name
= `LH Berlin`
im _weight = 30000.
41
Global network
of innovation
Static Constructor
CLASS <classname> DEFINITION.
PUBLIC SECTION.
CLASS-METHODS CLASS_CONSTRUCTOR.
ENDCLASS.
42
Global network
of innovation
* Example 1:
Automatically called
before the class is first
accessed
* Example 2:
43
Global network
of innovation
Principles Overview -7
Objects
Classes
Attributes
Methods
Instantiation, Garbage Collector
Working with Objects
Further Principles
44
Global network
of innovation
Encapsulation
Class as capsule for functions
Defined responsibilities within a capsule (class)
Defined interfaces using
Interfaces
45
Global network
of innovation
Data
Client
Run
Data
Server
46
Global network
of innovation
lcl _tank
lcl _airplane
lcl _client
fuel : i
fuel_max : i
get_fuel_level () : re_level
re_level = tank->get_fuel_level ( ).
get_fuel_level () : re_level
47
Global network
of innovation
1: get_fuel_level ( )
2: get_fuel_level ( )
re_level
re_level
48
Global network
of innovation
Attribute names
Method names
Event names
Type names
Constant names
ALIAS names
49
Global network
of innovation
Namespace : Example
CLASS lcl _airplane DEFINITION.
PUBLIC SECTION.
METHODS CONSTRUCTOR
IMPORTING im _name
TYPE string
im _weight TYPE I.
PRIVATE SECTION.
DATA name
TYPE string.
DATA weight TYPE I.
ENDCLASS.
CLASS cl _airplane IMPLEMENTATION.
METHOD CONSTRUCTOR.
DATA name TYPE string VALUE `-airplane`.
CONCATENATE
weight =
ENDMETHOD.
ENDCLASS.
im _weight.
50
51
Author/Filename
Global network
of innovation
Questions ?