簡體   English   中英

埃菲爾鐵塔:類型一致性,如何提供類型而不是實例

[英]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

編輯(20190405-11:26 UTC)

如屏幕截圖所示,用{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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM