Eiffel:如何创建和使用 UTIL class,或 "call static method from class"
Eiffel: how do I create and use an UTIL class, or "call static method from class"
如 my post 所述,我想创建一个带有 never_both 函数的 UTIL class。
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
如果你想在不创建相应对象的情况下使用某个功能,则应将其标记为class
功能。这是在具有相同关键字的特征后置条件中完成的:
foo ...
do
...
ensure
instance_free: class
...
end
之后,可以在无对象调用中使用该功能{BAR}.foo ...
。
符号 ({BAR}).qux
不表示无对象调用。它是对 TYPE [BAR]
类型的目标对象的对象调用。对象描述类型 BAR
.
如 my post 所述,我想创建一个带有 never_both 函数的 UTIL class。
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
如果你想在不创建相应对象的情况下使用某个功能,则应将其标记为class
功能。这是在具有相同关键字的特征后置条件中完成的:
foo ...
do
...
ensure
instance_free: class
...
end
之后,可以在无对象调用中使用该功能{BAR}.foo ...
。
符号 ({BAR}).qux
不表示无对象调用。它是对 TYPE [BAR]
类型的目标对象的对象调用。对象描述类型 BAR
.