Describe what a collaborator can do
A delivery workflow needs to send a message, but it should not need to know whether the message goes to an email adapter, a log, or a test fake. An interface defines the capability; classes implement it.
Define a contract
INTERFACE lif_notifier.
METHODS send
IMPORTING iv_message TYPE string
RETURNING VALUE(result) TYPE string.
ENDINTERFACE.
The interface names a method and its parameter contract. It does not prescribe how the message is delivered.
Implement the contract
CLASS lcl_log_notifier DEFINITION.
PUBLIC SECTION.
INTERFACES lif_notifier.
ENDCLASS.
CLASS lcl_log_notifier IMPLEMENTATION.
METHOD lif_notifier~send.
result = |Logged: { iv_message }|.
ENDMETHOD.
ENDCLASS.
Interface methods are implemented using the interface component name. Callers typed against the interface depend on the capability rather than a concrete class.
When it helps
Use an interface when multiple implementations are plausible, when a consumer should not depend on implementation details, or when tests need to substitute a controlled fake. A one-class toy that will never vary may not need an interface yet; introduce abstraction for a reason, not just to add files.
Practice
Declare lif_notifier, implement it in lcl_log_notifier, call the method and assign the returned text to result. Add context-specific output. The browser checks syntax fragments only; it does not run ABAP.
Version note: Interface syntax is part of ABAP Objects. APIs a class can call differ under ABAP Cloud’s released-object rules; verify against the target environment.
Sources
- SAP Samples, ABAP Object Orientation: interfaces
- SAP Samples, ABAP for Cloud Development
Developer practice · ABAP
Practice: implement the delivery notifier interface
Declare an interface with a send method, make a class implement it, and use the interface method to create a result message.
This choice changes the output pattern checked here: WRITE belongs in a classic executable report, while out->write( ) uses the supplied output reference in an ABAP Cloud class-run method. It does not switch the language version of the other code; check release and API availability in your target system.
Complete the task and include the output statement shown for your selected environment. Variable names can differ if you use them consistently. This browser checker checks structure only; it does not compile or run ABAP.
0 required structures detected · 0 checks
Write your solution, then check its structure.
One possible solution
INTERFACE lif_notifier.
METHODS send IMPORTING iv_message TYPE string RETURNING VALUE(result) TYPE string.
ENDINTERFACE.
CLASS lcl_log_notifier DEFINITION.
PUBLIC SECTION.
INTERFACES lif_notifier.
ENDCLASS.
CLASS lcl_log_notifier IMPLEMENTATION.
METHOD lif_notifier~send.
result = |Logged: { iv_message }|.
ENDMETHOD.
ENDCLASS.
DATA(notifier) = NEW lcl_log_notifier( ).
DATA(result) = notifier->lif_notifier~send( iv_message = 'Parcel ready' ).
WRITE result.out->write( result ).These are context-specific output examples. In your own program, use the result variable from your solution and the output mechanism available in that program.