4

I know that ABAP Objects are kinda old but as far as my knowledge goes you still have to use at least two "sections" to create a complete class.

ABAP:

CLASS CL_MYCLASS DEFINITION.
    PUBLIC SECTION.
        ...
    PROTECTED SECTION.
        ...
    PRIVATE SECTION.
        ...
ENDCLASS.

CLASS CL_MYCLASS IMPLEMENTATION.
    ...
ENDCLASS.

Java:

public class MyClass {

    <visibility> <definition> {
        <implementation>
    }

}

Wouldn't it make development easier/faster by having a combination of both like most modern languages have?

What are the reasons for this separation?

  • I don't think ABAP qualifies as a "*modern language*" – Random Dev Mar 11 '16 at 12:57
  • Did I imply that? I think not. I just claimed that most modern languages use such a mixture ^^ –  Mar 11 '16 at 13:00
  • yeah but aside from the designers who should be able to answer this for you? It's just asking for opinions and this is considered OT here – Random Dev Mar 11 '16 at 13:35
  • I did not design ABAP but I would say that they looked to C/C++ where definition and implementation are separated as well: http://stackoverflow.com/questions/333889/why-have-header-files-and-cpp-files-in-c Which implies that besides of the idea of separating "what the class does" from its "how", there is no special advantage or reason for it (if you really want to reuse only the "what the class does" part, you would use abstractions like abstract classes, or interfaces. – rplantiko Mar 11 '16 at 13:41
  • @Carsten ABAP Objects: ca. 2001. Java: 1995. Now which one is more modern? :-) – vwegert Mar 11 '16 at 13:44
  • @vwegert you think it's about age? AFAIK it's heavily based on COBOL which is about 1960 or so ... also: the answer is *neither* Java nor ABAP is a modern language ... at all ^^ - anyway sorry for the snide side remarks (I could not help myself here) and have a nice day – Random Dev Mar 11 '16 at 13:52
  • @Carsten No offense taken and no, I don't think it's about age - but after a while, this kind of remarks does get tiresome... – vwegert Mar 11 '16 at 13:54
  • @Carsten I actually don't know. That's why I asked here. Maybe there is an official explanation out there I haven't heard of. Maybe there were discussions about that topic in the release times. Or even simpler: There is a big advantage (performance/documentation/whatsoever) in this concept that I can't imagine as a user. –  Mar 11 '16 at 14:09

2 Answers2

4

Easier/faster for the human (maybe), but costly for the compiler: It has to sift through the entire code to determine the structure of the class and its members, whereas in the current form, it only needs to compile the definition to determine whether a reference is valid. ABAP is not the only language that separates definition from implementation: Pascal did so for units, and Object Pascal for classes. One might argue that C++ allows for same construct without specifying an implementation section when you're not using inline member function declarations.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • 1
    I would argue the "easier / faster for the human". A well-done header file is a very useful documentation for a library, in and of itself. With e.g. Java, you need additional tools (javadoc) to extract a self-documenting summary from the source (if you *have* the source...). – DevSolar Mar 11 '16 at 13:43
0

Maybe another reason:

Most (?) classes are not defined with manual written code, but via SE24. There you define the interface in one dynpro and write the code in another one.

Internally the interfaces are stored in one source, the code is stored in another source. So it is reasonable to separate the interface and the implementation.

knut
  • 27,320
  • 6
  • 84
  • 112
  • That is not entirely accurate. Each method implementation is stored in a separate include, and depending on the version, the interface part is split up into several includes (public/protected/private section, macros, types, ...) as well. In any case, since the tooling was only introduced after the language elements were specified, that's probably not the main reason. – vwegert Mar 13 '16 at 08:11