Table of Contents

Open all
Close all
Preface
17
Target Group and Prerequisites
17
Structure of the Book
17
Conventions
19
Source Code and Examples
20
Acknowledgments
20
1 Introduction to Object-Oriented Programming
23
1.1 The Need for a Better Abstraction
23
1.1.1 The Evolution of Programming Languages
23
1.1.2 Moving Toward Objects
24
1.2 Classes and Objects
25
1.2.1 What Are Objects?
25
1.2.2 Introducing Classes
26
1.2.3 Defining a Class Interface
28
1.3 Establishing Boundaries
29
1.3.1 Encapsulation and Implementation Hiding
29
1.3.2 Understanding Visibility Sections
31
1.4 Reuse
31
1.4.1 Composition
31
1.4.2 Inheritance
32
1.4.3 Polymorphism
33
1.5 Object Management
34
1.6 UML Tutorial: Class Diagram Basics
35
1.6.1 What Are Class Diagrams?
36
1.6.2 Classes
37
1.6.3 Attributes
37
1.6.4 Operations
38
1.6.5 Associations
39
1.6.6 Notes
40
1.7 Summary
40
2 Working with Objects
41
2.1 Defining Classes
41
2.1.1 Creating a Class
42
2.1.2 Component Declarations
43
2.1.3 Implementing Methods
50
2.2 Working with Objects
51
2.2.1 Object References
52
2.2.2 Creating Objects
52
2.2.3 Object Reference Assignments
53
2.2.4 Accessing Instance Components
55
2.2.5 Accessing Class Components
58
2.2.6 Working with Events
60
2.2.7 Working with Functional Methods
64
2.2.8 Chaining Method Calls Together
67
2.3 Building Your First Object-Oriented Program
70
2.3.1 Creating the Report Program
70
2.3.2 Adding in the Local Class Definition
74
2.4 Working with Global Classes
76
2.4.1 Understanding the Class Pool Concept
76
2.4.2 Getting Started with the Class Builder Tool
76
2.4.3 Creating Global Classes
78
2.4.4 Using the Form-Based Editor
80
2.4.5 Using the Source Code Editor
88
2.5 Developing Classes Using ABAP Development Tools
88
2.5.1 What Is Eclipse?
89
2.5.2 Setting Up the ABAP Development Tools Environment
89
2.5.3 Working with the ABAP Development Tools Class Editor
93
2.6 Working with Constructor Expressions
101
2.7 UML Tutorial: Object Diagrams
104
2.8 Summary
106
3 Encapsulation and Implementation Hiding
107
3.1 Lessons Learned from Procedural Programming
107
3.1.1 Decomposing the Functional Decomposition Process
108
3.1.2 Case Study: A Procedural Code Library in ABAP
110
3.1.3 Moving Toward Objects
115
3.2 Data Abstraction with Classes
116
3.3 Defining Component Visibilities
117
3.3.1 Working with Visibility Sections
118
3.3.2 Understanding the Friend Concept
121
3.4 Hiding the Implementation
123
3.5 Designing by Contract
124
3.6 UML Tutorial: Sequence Diagrams
125
3.7 Summary
126
4 Object Initialization and Cleanup
129
4.1 Understanding the Object Creation Process
129
4.2 Working with Constructors
133
4.2.1 Defining Constructors
134
4.2.2 Understanding How Constructors Work
134
4.2.3 Class Constructors
136
4.3 Taking Control of the Instantiation Process
137
4.3.1 Controlling the Instantiation Context
138
4.3.2 Implementing the Singleton Pattern
139
4.3.3 Working with Factory Methods
141
4.4 Garbage Collection
143
4.5 Tuning Performance
144
4.5.1 Design Considerations
144
4.5.2 Lazy Initialization
144
4.5.3 Reusing Objects
145
4.5.4 Making Use of Class Attributes
146
4.6 UML Tutorial: State Machine Diagrams
146
4.7 Summary
147
5 Inheritance and Composition
149
5.1 Generalization and Specialization
149
5.1.1 Inheritance Defined
150
5.1.2 Defining Inheritance Relationships in ABAP Objects
151
5.1.3 Working with Subclasses
156
5.1.4 Inheritance as a Living Relationship
157
5.2 Inheriting Components
159
5.2.1 Designing the Inheritance Interface
159
5.2.2 Visibility of Instance Components in Subclasses
161
5.2.3 Visibility of Class Components in Subclasses
162
5.2.4 Redefining Methods
162
5.2.5 Instance Constructors
165
5.2.6 Class Constructors
166
5.3 The Abstract and Final Keywords
166
5.3.1 Abstract Classes and Methods
166
5.3.2 Final Classes
170
5.3.3 Final Methods
172
5.4 Inheritance Versus Composition
173
5.5 Working with ABAP Refactoring Tools
176
5.6 UML Tutorial: Advanced Class Diagrams, Part I
179
5.6.1 Generalizations
179
5.6.2 Dependencies and Composition
179
5.6.3 Abstract Classes and Methods
180
5.7 Summary
182
6 Polymorphism
183
6.1 Object Reference Assignments Revisited
183
6.1.1 Static and Dynamic Types
184
6.1.2 Casting
186
6.2 Dynamic Method Call Binding
189
6.3 Interfaces
191
6.3.1 Interface Inheritance Versus Implementation Inheritance
192
6.3.2 Defining Interfaces
193
6.3.3 Implementing Interfaces
197
6.3.4 Working with Interfaces
200
6.3.5 Nesting Interfaces
203
6.3.6 When to Use Interfaces
205
6.4 UML Tutorial: Advanced Class Diagrams, Part II
207
6.4.1 Interfaces
207
6.4.2 Providing and Required Relationships with Interfaces
208
6.4.3 Static Attributes and Methods
209
6.5 Summary
209
7 Component-Based Design Concepts
211
7.1 Understanding SAP’s Component Model
211
7.2 The Package Concept
214
7.2.1 Why Do You Need Packages?
214
7.2.2 Introducing Packages
215
7.2.3 Creating Packages Using the Package Builder
217
7.2.4 Embedding Packages
224
7.2.5 Defining Package Interfaces
225
7.2.6 Creating Use Accesses
228
7.2.7 Performing Package Checks
229
7.2.8 Restriction of Client Packages
231
7.3 Package Design Concepts
233
7.4 UML Tutorial: Package Diagrams
235
7.5 Summary
237
8 Error Handling with Exception Classes
239
8.1 Lessons Learned from Prior Approaches
239
8.1.1 Lesson 1: Exception Handling Logic Gets in the Way
239
8.1.2 Lesson 2: Exception Handling Requires Varying Amounts of Data
240
8.1.3 Lesson 3: The Need for Transparency
241
8.2 The Class-Based Exception Handling Concept
241
8.3 Creating Exception Classes
243
8.3.1 Understanding Exception Class Types
243
8.3.2 Local Exception Classes
244
8.3.3 Global Exception Classes
245
8.3.4 Defining Exception Texts
247
8.3.5 Mapping Exception Texts to Message Classes
249
8.4 Dealing with Exceptions
250
8.4.1 Handling Exceptions
250
8.4.2 Cleaning Up the Mess
254
8.5 Raising and Forwarding Exceptions
255
8.5.1 System-Driven Exceptions
255
8.5.2 Raising Exceptions Programmatically
256
8.5.3 Propagating Exceptions
260
8.5.4 Resumable Exceptions
263
8.6 UML Tutorial: Activity Diagrams
267
8.7 Summary
269
9 Unit Tests with ABAP Unit
271
9.1 ABAP Unit Overview
271
9.1.1 Unit Testing Terminology
272
9.1.2 Understanding How ABAP Unit Works
272
9.1.3 ABAP Unit and Production Code
274
9.2 Creating Unit Test Classes
274
9.2.1 Unit Test Naming Conventions
274
9.2.2 Generating Test Classes for Global Classes
275
9.2.3 Defining Test Attributes
276
9.2.4 Building Test Methods
277
9.2.5 Working with Fixtures
278
9.2.6 Working with Test Seams
278
9.2.7 Defining Reusable Test Classes
280
9.3 Assertions in ABAP Unit
280
9.3.1 Creating and Evaluating Custom Constraints
281
9.3.2 Applying Multiple Constraints
282
9.4 Managing Dependencies
283
9.4.1 Dependency Injection
283
9.4.2 Private Dependency Injection
284
9.4.3 Partially Implemented Interfaces
284
9.4.4 Working with Test Doubles
285
9.4.5 Other Sources of Information
287
9.5 Case Study: Creating a Unit Test in ABAP Unit
288
9.6 Executing Unit Tests
291
9.6.1 Integration with the ABAP Workbench
291
9.6.2 Creating Favorites in the ABAP Unit Test Browser
292
9.6.3 Integration with the Code Inspector
293
9.7 Evaluating Unit Test Results
294
9.8 Measuring Code Coverage
294
9.9 Moving Toward Test-Driven Development
296
9.10 Behavior-Driven Development
296
9.11 UML Tutorial: Use Case Diagrams
297
9.11.1 Use Case Terminology
297
9.11.2 An Example Use Case
298
9.11.3 The Use Case Diagram
299
9.11.4 Use Cases for Requirements Verification
300
9.11.5 Use Cases and Testing
301
9.12 Summary
301
10 Business Object Development with BOPF
303
10.1 What Is BOPF?
303
10.2 Anatomy of a Business Object
305
10.2.1 Nodes
306
10.2.2 Actions
310
10.2.3 Determinations
312
10.2.4 Validations
313
10.2.5 Associations
315
10.2.6 Queries
318
10.3 Working with the BOPF Client API
319
10.3.1 API Overview
320
10.3.2 Creating Business Object Instances and Node Rows
323
10.3.3 Searching for Business Object Instances
326
10.3.4 Updating and Deleting Business Object Node Rows
327
10.3.5 Executing Actions
328
10.3.6 Working with the Transaction Manager
329
10.4 Where to Go from Here
330
10.4.1 Looking at the Big Picture
330
10.4.2 Enhancing Business Objects
331
10.5 UML Tutorial: Advanced Sequence Diagrams
331
10.5.1 Creating and Deleting Objects
332
10.5.2 Depicting Control Logic with Interaction Frames
333
10.6 Summary
334
11 ABAP RESTful Application Programming Model
335
11.1 Introduction
335
11.1.1 What Is the ABAP RESTful Application Programming Model?
335
11.1.2 Relationship to SAP Gateway
337
11.1.3 Business Object Runtime
338
11.1.4 Behavior Definitions
340
11.1.5 Model Classes
342
11.2 CDS and SAP Gateway Service Bindings
347
11.2.1 CDS Views
347
11.2.2 Associations
348
11.3 Modeling Behavior Using Object-Oriented Techniques
350
11.3.1 Creating the Service
350
11.3.2 Object-Oriented Implementation
360
11.4 Summary
370
12 ABAP Cloud
371
12.1 Introduction to SAP Business Technology Platform
372
12.1.1 What Is SAP Business Technology Platform?
372
12.1.2 Core Capabilities of SAP Business Technology Platform
374
12.1.3 ABAP and SAP Business Technology Platform
376
12.2 ABAP Environment Overview
377
12.2.1 Core Concepts
378
12.2.2 Key Architectural Components
383
12.3 Setting Up Your Cloud Development Environment
386
12.3.1 Transitioning from On-Premise to Cloud Development
386
12.3.2 Creating Your SAP BTP ABAP Environment
388
12.4 Case Study: Implementing ABAP RESTful Application Programming Model Elements via ABAP Cloud
395
12.4.1 Recreation of ABAP RESTful Application Programming Model Objects
396
12.4.2 Publishing and Consuming the Service
397
12.5 Summary
397
13 Best Practices and Design Patterns
399
13.1 Object-Oriented Analysis and Design
399
13.2 Creational Patterns
401
13.2.1 When to Use Creational Patterns in ABAP
403
13.2.2 Singleton Pattern
404
13.2.3 Factory Method Pattern
405
13.3 Structural Patterns
408
13.3.1 When to Use Structural Patterns in ABAP
409
13.3.2 Adapter Pattern
411
13.3.3 Decorator Pattern
414
13.4 Behavioral Patterns
419
13.4.1 When to Use Behavioral Patterns in ABAP
421
13.4.2 Strategy Pattern
421
13.5 Summary
425
A Installing the Eclipse IDE
427
A.1 Installing the Java SDK
427
A.2 Installing Eclipse
428
A.3 Installing the ABAP Development Tools
430
A.4 Where to Go to Find Help
432
B The Authors
433
Index
435