14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2

New Language Features in ABAP 7.4

the new design to put the first value in the RETURNING parameter and the last three

values in EXPORTING parameters, but that seems a bit silly. You could just return a

structure of four values instead.) Nonetheless, because this is a new feature of 7.4

that you might occasionally find useful, it was important to mention it here.

2.7.3 Changes to Interfaces

This section discusses how SAP has tried to take some of the pain out of your

daily usage of interfaces in OO programming in 7.4. As you know, an interface is

a collection of data declaration and method names and signatures. If a class implements

any given interface, then it has to redefine all the interface methods. This

is all good, but prior to 7.4 the problem was that some standard interfaces had a

really big list of methods, only some of which were relevant, and so you had to go

through the irrelevant methods, redefining them to have blank implementations.

As of 7.4, if you are creating an interface and think that some of the methods

might not be needed by all classes that implement the interface, then you can say

so in the interface definition. An example of this is shown in Listing 2.72.

INTERFACE scary_behavior.

METHODS: scare_small_children,

sells_mortgages DEFAULT FAIL,

hide_under_bed DEFAULT IGNORE,

is_fire_breather

DEFAULT IGNORE

RETURNING rf_yes_it_is TYPE abap_bool.

ENDINTERFACE. "Scary Behavior

Listing 2.72 Defining an Interface with Optional Methods

This is an interface all monster classes should implement. Naturally, all monsters

should be able to scare children; thus, do not give that method definition any

addition. This means that each class implementing that interface is forced to redefine

the method by the syntax check. On the other hand, most monsters will not

sell mortgages (just the worst of the wo rst monsters), so do not force all the

classes to implement this method. Because you have added DEFAULT FAIL if a program

using an instance of a monster that implements this interface tries to make

the monster sell mortgages, and the meth od has not been implemented, then a

runtime error occurs (CX_SY_DYN_CALL_ILLEGAL_METHOD).

Similarly, do not force all monster classes to hide under beds; obviously, the ones

that are a thousand feet tall have problems in this area. By adding DEFAULT IGNORE

128

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!