Progress-4GL中的Final/const关键字等效项 [英] Final/const keyword equivalent in Progress-4GL

查看:58
本文介绍了Progress-4GL中的Final/const关键字等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个Java中具有不变成员的类,我会这样做:

If I had a class with immutable members in Java, I would do this:

class MyClass {
    private final String name;
    private final int id;
    myClass(String name, int id) {
        this.name = name;
        this.id = id;
    }
    String getName() { return name; }
    int getId() { return id; }
}

在Progress-4GL中,您通常会看到类似以下内容的内容:(请不要讲匈牙利书写法.我也讨厌它,但是它在Progress社区中很常见,所以我可以忍受.)

In Progress-4GL, you'd typically see something like this: (Please, no lectures on Hungarian Notation. I hate it too, but it's very common in the Progress community, so it's something I just live with.)

CLASS MyClass :

    DEFINE VARIABLE mcName as CHARACTER NO-UNDO.
    DEFINE VARIABLE miId   as INTEGER   NO-UNDO.

    CONSTRUCTOR PUBLIC MyClass(INPUT ipcName AS CHARACTER,
                               INPUT ipiId AS INTEGER):
        ASSIGN mcName = ipcName
               miId   = ipiID.
    END. /* constructor(char,int)*/
END CLASS. /* MyClass */

在进度10.2B中,我被告知,他们增加了进行常量/最终变量的能力.但是,我无法在任何地方找到对此的任何引用.在我的架构师(版本10.2A)中,我确实看到 FINAL 被视为关键字.但是它背后的文档使我难以理解.

I was told in that in Progress 10.2B, they added the ability to make constants/final variables. However, I am unable to find any reference to it anywhere. In my Architect (version 10.2A) I do see that FINAL is considered a keyword. But the documentation behind it simply eludes me.

如果您曾经尝试搜索进度"文档,就会知道我的困境.

And if you've ever tried to search for Progress documentation, you know my dilemma.

如何在Progress 10.2B中执行不可变变量?我有什么需要注意的散剂吗?

谢谢!

编辑1 我在 FINAL 上找到了文档.它似乎仅适用于类和方法.我目前的做法是

EDIT 1 I found documentation on FINAL. It appears to only apply to classes and methods. My current approach is

CLASS ImmutableString :
    DEFINE PRIVATE VARIABLE mcValue AS CHARACTER NO-UNDO.

    CONSTRUCTOR PUBLIC ImmutableString(INPUT ipcValue AS CHARACTER) :
        ASSIGN mcValue = ipcValue.
    END.

    METHOD PUBLIC CHARACTER getValue() :
        RETURN mcValue. /* Is a defensive copy required? */
    END METHOD.
END CLASS.

推荐答案

您还可以创建带有公共"GET"和私有"SET"的公共属性:

You could also create a public property with a public "GET" and a private "SET":

   DEF PUBLIC PROPERTY Value AS CHAR NO-UNDO
      GET.
      PRIVATE SET.

   CONSTRUCTOR PUBLIC ImmutableString(INPUT ipcValue AS CHARACTER) :
       Value = ipcValue.
   END.

这少了一些代码,并且做同样的事情.

That's a little less code and does the same thing.

已编辑以更改属性名称以匹配原始海报的示例.

EDITED to change the property name to match the original poster's example.

这篇关于Progress-4GL中的Final/const关键字等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆