[英]Eiffel: a way to check type conformance with a given CLASS_NAME
I'm trying to do something as 我正在尝试做一些事情
work (a_father: FATHER)
do
if a_father.conforms_to ({DEVELOPER}) then
a_father.code
else
a_father.change_job ({DEVELOPER})
end
end
the compilation works, but in my implementation @runtime it doesn't pass. 编译工作正常,但是在我的实现@runtime中,它没有通过。 What did I mistype? 我输错了什么?
The problem in your example is that you are trying to see whether the type FATHER
(type of the object a_father
) conforms to the type TYPE [DEVELOPER]
(the type of the object {DEVELOPER}
). 您的示例中的问题是您试图查看FATHER
类型(对象a_father
的类型)是否符合TYPE [DEVELOPER]
类型(对象{DEVELOPER}
的类型)。
What you should do is: 您应该做的是:
if a_father.generating_type.is_conforming_to ({DEVELOPER}) then
hence comparing TYPE [FATHER]
with TYPE [DEVELOPER]
. 因此,将TYPE [FATHER]
与TYPE [DEVELOPER]
。
Note that I would assume that it would work by replacing is_conforming_to
by conforms_to
, but class TYPE
introduced this routine is_conforming_to
with a more specific argument type. 请注意,我会认为它会通过更换工作is_conforming_to
通过conforms_to
,但类TYPE
推出这个程序is_conforming_to
有一个更具体的参数类型。
I'd better use a built-in mechanism to check object type conformance: 我最好使用内置机制来检查对象类型的符合性:
if attached {DEVELOPER} a_father as dev then
dev.code
else
a_father.rest
end
And use the same approach in the precondition: 并在前提条件中使用相同的方法:
attached {RELATED_DB_ENTITY} a_relationship_entity
The object test does what you would like to: it checks that the type of the object attached to argument a_relationship_entity
conforms to type RELATED_DB_ENTITY
. 对象测试执行您a_relationship_entity
:它检查附加到参数a_relationship_entity
的对象的类型a_relationship_entity
符合RELATED_DB_ENTITY
类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.