简体   繁体   English

为什么 ABAP 将类分为实现和定义?

[英]Why does ABAP divide classes into implementation and definition?

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 对象有点旧,但据我所知,您仍然必须至少使用两个“部分”来创建一个完整的类。

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?这种分离的原因是什么?

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. ABAP 并不是将定义与实现分开的唯一语言: Pascal是针对单元这样做的,而Object Pascal 是针对类的。 One might argue that C++ allows for same construct without specifying an implementation section when you're not using inline member function declarations.有人可能会争辩说,当您不使用内联成员函数声明时,C++ 允许在不指定实现部分的情况下使用相同的构造。

Maybe another reason:也许还有一个原因:

Most (?) classes are not defined with manual written code, but via SE24.大多数 (?) 类不是用手动编写的代码定义的,而是通过 SE24 定义的。 There you define the interface in one dynpro and write the code in another one.在那里您在一个 dynpro 中定义接口并在另一个 dynpro 中编写代码。

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.所以把接口和实现分开是合理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM