Skip to content

Lesson 4 Companion — Classes, Objects & Encapsulation ​

1. Why this version differs from older beginner OOP material ​

A common teaching pattern starts with public mutable attributes and fixes them later. This course starts with private state because it avoids establishing a pattern we do not want students to carry into application design.

2. FINAL class ​

FINAL prevents subclassing. A simple domain class can be final until inheritance is intentionally introduced later.

3. Object creation ​

Modern ABAP supports:

abap
DATA(product) = NEW zcl_product_###( ... ).

Older CREATE OBJECT syntax still exists, but NEW is expression-friendly and fits modern ABAP style.

4. me-> ​

Use it when it improves clarity, especially where an attribute and parameter share a name.

5. Reference implementation ​

The complete Product definition/implementation is in the Content file. A strong implementation should ensure stock never becomes negative through its public methods.

6. Encapsulation is not “getters and setters everywhere” ​

The stronger principle is:

text
private representation
+
meaningful public behavior

A setter is appropriate only when unrestricted replacement really belongs to the object's API.

SAP references ​