forked from moreus/ABAPDesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zdp_templatemethod.abap
100 lines (83 loc) · 2.19 KB
/
zdp_templatemethod.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
*&---------------------------------------------------------------------*
*& Report ZDP_TEMPLATEMETHOD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zdp_templatemethod.
CLASS template_sandwich DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS: prepare_sandwich FINAL.
PROTECTED SECTION.
METHODS: add_butter.
METHODS: add_extra ABSTRACT.
METHODS: add_veggetables ABSTRACT.
PRIVATE SECTION.
METHODS: slice_break.
ENDCLASS.
CLASS template_sandwich IMPLEMENTATION.
METHOD add_butter.
WRITE: / 'Add thin layer of butter'.
ENDMETHOD.
METHOD slice_break.
WRITE: / 'Slice Break.'.
ENDMETHOD.
METHOD prepare_sandwich.
slice_break( ).
add_butter( ).
add_extra( ).
add_veggetables( ).
ENDMETHOD.
ENDCLASS.
CLASS cheese_sandwich DEFINITION INHERITING FROM template_sandwich.
PUBLIC SECTION.
PROTECTED SECTION.
METHODS: add_extra REDEFINITION.
METHODS: add_veggetables REDEFINITION.
METHODS: add_butter REDEFINITION.
PRIVATE SECTION.
ENDCLASS.
CLASS cheese_sandwich IMPLEMENTATION.
METHOD add_butter.
WRITE: / 'Add thick layer of butter'.
ENDMETHOD.
METHOD add_extra.
WRITE:/ 'Add slices of camenbert'.
ENDMETHOD.
METHOD add_veggetables.
WRITE:/ 'Add tomato slices'.
ENDMETHOD.
ENDCLASS.
CLASS ham_sandwich DEFINITION INHERITING FROM template_sandwich.
PUBLIC SECTION.
PROTECTED SECTION.
METHODS: add_extra REDEFINITION.
METHODS: add_veggetables REDEFINITION.
PRIVATE SECTION.
ENDCLASS.
CLASS ham_sandwich IMPLEMENTATION.
METHOD add_extra.
WRITE: / 'Add slice of ham'.
ENDMETHOD.
METHOD add_veggetables.
WRITE: / 'Add salad leaves'.
WRITE: / 'Add onions'.
ENDMETHOD.
ENDCLASS.
CLASS mainapp DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
main.
ENDCLASS.
CLASS mainapp IMPLEMENTATION.
METHOD main.
DATA: sandwich TYPE REF TO template_sandwich.
CREATE OBJECT sandwich TYPE cheese_sandwich.
sandwich->prepare_sandwich( ).
CREATE OBJECT sandwich TYPE ham_sandwich.
sandwich->prepare_sandwich( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
mainapp=>main( ).