代码之家  ›  专栏  ›  技术社区  ›  OneWorld

在alfa中,一个属性可以用于多个类别吗?

  •  1
  • OneWorld  · 技术社区  · 8 年前

    doctor 可以属于 subjectCat (试图访问的用户)或 resourceCat (受试者试图进入的体检的转诊医生)。

    在我看来,为了支持这两种情况,我需要定义 医生 对于每个类别单独:

    namespace subject {
         namespace doctor {
              attribute id {
                        category = subjectCat
                        id = "id"
                        type = string
              }
              attribute lastname {
                        category = subjectCat
                        id = "lastname"
                        type = string
              }
              //and 20 more attributes...
          }
    }
    
    
    namespace resource {
         namespace doctor {
              attribute id {
                        category = resourceCat //this line is the only difference
                        id = "id"
                        type = string
              }
              attribute lastname {
                        category = resourceCat //this line is the only difference
                        id = "lastname"
                        type = string
              }
              //and 20 more attributes...
          }
    }
    

    这很麻烦,而且有很多冗余。有什么我可以避免的吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   David Brossard    8 年前

    你是对的。您将重新定义属性。在某种程度上,您使用的是信息模型中的同一个对象(例如医生),但在一种情况下,该对象(医生)充当一个主题。在另一种情况下,它充当您正在保护的对象,例如

    • 医生可以查看分配给他们的患者的病历。
    • 人力资源部的员工可以查看医生的工资。

    是的,这意味着您必须在多个类别中定义属性本身。只要名称空间和名称的组合保持唯一性,您仍然可以利用名称空间结构。

    你可以的 acme.user.staff.doctor 和属性 name . 你可以那么做 acme.object.doctor 和属性 名称 .

    请注意,Eclipse也允许您自动完成:

    Auto-completing attribute names in ALFA inside Eclipse