[英]Eiffel: type conformance, how to give a type instead of an instance
I don't understand why there are like 2 generating_type
kinds, the one with exclamation point, and the other not. 我不明白为什么会有2种generating_type
类型,一种带有感叹号,而另一种则没有。
I have a function returning a DB_SERVICE[G]
from a given instance from a collection of db_services
so that from another service I can retrieve it and call it. 我有一个函数,它从db_services
集合的给定实例中返回DB_SERVICE[G]
,以便可以从另一个服务中检索它并调用它。 When I pass an instance generating_type
to that function, the conforms_to
returns True, as when I give ({ENUMERATE}).generating_type
it doesn't. 当我将实例generating_type
传递给该函数时, conforms_to
返回True,就像我给出({ENUMERATE}).generating_type
时没有那样。
Why is that so? 为什么会这样?
-- Humanly unreadable
if attached {ENUMERATE_DB_SERVICE} {SIT_ENVIRONMENT}.app_instance.db_service_from_entity_type (item_prototype.charge_unit_relationship.secondary_prototype.an_index_relationship.secondary_prototype.generating_type) as l_enum_dbs then
-- Humanly readable but not working
if attached {ENUMERATE_DB_SERVICE} {SIT_ENVIRONMENT}.app_instance.db_service_from_entity_type (({ENUMERATE}).generating_type) as l_enum_dbs then
My function 我的功能
db_service_from_entity_type (an_entity_type: TYPE[detachable DB_ENTITY]): detachable like db_services.item
do
across
db_services as l_dbs
until
Result /= Void
loop
if l_dbs.item.item_prototype.generating_type.conforms_to (an_entity_type) then
Result := l_dbs.item
end
end
ensure
service_found: attached Result
end
As the screenshot shows, giving {ENUMERATE}
instead of ({ENUMERATE}).generating_type
doesn't work either 如屏幕截图所示,用{ENUMERATE}
代替({ENUMERATE}).generating_type
也不起作用
generating_type
returns a dynamic type of an object. generating_type
返回对象的动态类型。 Therefore, ({ENUMERATE}).generating_type
produces TYPE [!TYPE [!ENUMERATE]]
. 因此, ({ENUMERATE}).generating_type
产生TYPE [!TYPE [!ENUMERATE]]
。 But you need just TYPE [ENUMERATE]
. 但是您只需要TYPE [ENUMERATE]
。 This can be achieved by removing the call to generating_type
and using a detachable version of the type: {detachable ENUMERATE}
. 这可以通过删除对generating_type
的调用并使用类型的可分离版本: {detachable ENUMERATE}
。
The corresponding object test would look like 相应的对象测试看起来像
if attached {ENUMERATE_DB_SERVICE} {SIT_ENVIRONMENT}.app_instance.db_service_from_entity_type
({detachable ENUMERATE}) as l_enum_dbs then
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.