[英]Eiffel: type conformance, how to give a type instead of an instance
我不明白為什么會有2種generating_type
類型,一種帶有感嘆號,而另一種則沒有。
我有一個函數,它從db_services
集合的給定實例中返回DB_SERVICE[G]
,以便可以從另一個服務中檢索它並調用它。 當我將實例generating_type
傳遞給該函數時, conforms_to
返回True,就像我給出({ENUMERATE}).generating_type
時沒有那樣。
為什么會這樣?
-- 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
我的功能
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
如屏幕截圖所示,用{ENUMERATE}
代替({ENUMERATE}).generating_type
也不起作用
generating_type
返回對象的動態類型。 因此, ({ENUMERATE}).generating_type
產生TYPE [!TYPE [!ENUMERATE]]
。 但是您只需要TYPE [ENUMERATE]
。 這可以通過刪除對generating_type
的調用並使用類型的可分離版本: {detachable ENUMERATE}
。
相應的對象測試看起來像
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.