【问题标题】:Eiffel: how do I create and use an UTIL class, or "call static method from class"Eiffel:如何创建和使用 UTIL 类,或“从类中调用静态方法”
【发布时间】:2018-10-12 11:13:04
【问题描述】:

正如my post 描述的那样,我想创建一个带有 never_both 函数的 UTIL 类。

class
    UTIL

create
    default_create

feature -- could be in class BOOLEAN

    double_implies, reversible_implies, never_both (a, b: BOOLEAN): BOOLEAN
            -- Into boolean class with never_with
        do
            if a and b then
                Result := False
            else
                Result := True
            end
        end

end

当我使用它时

invariant
    never_both: {UTIL}.never_both (attached last_error, attached last_success_message)

编译器抱怨出现VUNO 错误

never_both used in the non-object call is not a class feature.

我看到了 2 个关于对象创建的符号 - {UTIL}.never_both (a, b) - ({UTIL}).never_both (a, b)

它们有什么区别?

如果可能的话,如何在 Eiffel 中创建一个应用程序范围(如果您愿意,甚至可以是全球范围内!)对象以供此 UTIL 使用?!

我知道这是一个 TUPLE 问题,所以我把它们放在 Bold

【问题讨论】:

    标签: createprocess eiffel


    【解决方案1】:

    如果您想在不创建相应对象的情况下使用某个功能,则应将其标记为class 功能。这是在具有相同关键字的特征后置条件中完成的:

    foo ...
        do
              ...
        ensure
            instance_free: class
            ...
        end
    

    之后,该功能可用于无对象调用{BAR}.foo ...

    符号({BAR}).qux 不表示无对象调用。它是对TYPE [BAR] 类型的目标对象的对象调用。该对象描述了BAR的类型。

    【讨论】:

      猜你喜欢
      • 2016-01-02
      • 1970-01-01
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 2013-01-15
      • 2023-03-13
      相关资源
      最近更新 更多