Interface link type constraints(接口链接类型约束(Interface link type constraints))¶
An interface link type constraint defines an object-to-object relationship common across all object types implementing an interface. Users can specify a description for the link and an API name for the link type to use as a reference in code. When an object implements an interface with an interface link type constraint, concrete link types on the object type are used to fulfill interface link type constraints.

As shown in the example above, to model the relationship between a facility and the airlines it serves, the Facility interface declares an optional one-to-many link type constraint between any object that implements the Facility interface and the Airline object type. This means that if the implementing object type (for example Airport) has a concrete link type to the Airlines object type, that link can be accessed through the interface link type API name.
Link type constraints¶
Link type constraints define the parameters of an interface link type. All implementing object types must have a link that satisfies these constraints if the link type is required. These parameters include the following:
- Link target type: An interface or an object type.
- Target: A specific interface or object type.
- Cardinality: One-to-one or one-to-many.
- Whether or not the link is required as part of object type implementation.
Link target: Interface¶
You should use a link target of type interface when you want to model the relationship between two abstract object types.
For example, you can use an interface link target to model the relationship between Facility and the Alert where they occur. Because there are several kinds of facilities and several kinds of alerts, it would be impossible to model the connection between the two if you could only use a single object type for each end of the link. Instead, you can model this relationship by defining a Facility interface, an Alert interface, and an interface link on Facility that is set to link to the Alert interface. You can then define an Airport object type that implements the Facility interface and a Flight Alert object that implements the Alert interface. From there, you can define a concrete link type from Airport to Flight Alert to satisfy the Facility interface’s link type constraint.
Link target: Object type¶
You should use a link target of type object type when the relationship between the interface and the target is concrete and the specificity should be enforced by the link type constraint.
For example, you could define a Facility interface that links to the Airlines object type. This interface link would model the fact that no matter what the facility type is, you expect it to have a link to the specific airlines that it serves.
Cardinality¶
Interface link types can further be specified to have a ONE or MANY cardinality. These cardinalities are analogous to one-to-one and one-to-many modeling, respectively. A ONE cardinality indicates that each object implementing the interface should link to one object of the target type. A MANY cardinality indicates that each object implementing the interface may link to any number of objects of the target type.
You should decide between using ONE or MANY based on the modeling needs for your Ontology. In some cases, it may make more sense to restrict the cardinality of the link to a single object. For example, you may want to model the relationship between a Driver's License and a Person as a SINGLE cardinality link since each license can only belong to a single concrete individual. If the relationship allows for more flexibility, such as with a Company and its Shareholders, you may want to use a MANY cardinality link to signify that each company can have one or more concrete shareholders.
中文翻译¶
接口链接类型约束(Interface link type constraints)¶
接口链接类型约束定义了实现同一接口的所有对象类型之间共有的对象到对象关系。用户可以为链接添加描述,并为链接类型指定API名称,以便在代码中引用。当某个对象实现了带有接口链接类型约束的接口时,该对象类型上的具体链接类型将用于满足这些接口链接类型约束。

如上例所示,为了建模设施与其服务的航空公司之间的关系,Facility接口声明了一个可选的一对多链接类型约束,该约束作用于任何实现Facility接口的对象与Airline对象类型之间。这意味着,如果实现该接口的对象类型(例如Airport)与Airlines对象类型之间存在具体链接,那么该链接可以通过接口链接类型的API名称进行访问。
链接类型约束(Link type constraints)¶
链接类型约束定义了接口链接类型的参数。如果链接类型是必需的,则所有实现该接口的对象类型都必须拥有满足这些约束的链接。这些参数包括:
- 链接目标类型(Link target type): 一个接口或一个对象类型。
- 目标(Target): 特定的接口或对象类型。
- 基数(Cardinality): 一对一或一对多。
- 该链接是否为对象类型实现中的必需部分。
链接目标:接口(Interface)¶
当您需要建模两个抽象对象类型之间的关系时,应使用类型为interface的链接目标。
例如,您可以使用接口链接目标来建模Facility与其发生地Alert之间的关系。由于存在多种类型的设施和多种类型的警报,如果链接两端只能使用单一对象类型,则无法建模两者之间的连接。相反,您可以通过定义一个Facility接口、一个Alert接口,以及在Facility上设置一个指向Alert接口的接口链接来建模这种关系。然后,您可以定义一个实现Facility接口的Airport对象类型,以及一个实现Alert接口的Flight Alert对象。在此基础上,您可以定义一个从Airport到Flight Alert的具体链接类型,以满足Facility接口的链接类型约束。
链接目标:对象类型(Object type)¶
当接口与目标之间的关系是具体的,并且需要通过链接类型约束来强制执行这种具体性时,应使用类型为object type的链接目标。
例如,您可以定义一个指向Airlines对象类型的Facility接口。这个接口链接体现了这样一个事实:无论设施类型是什么,都期望它拥有指向其所服务的特定航空公司的链接。
基数(Cardinality)¶
接口链接类型可以进一步指定为ONE或MANY基数。这些基数分别类似于一对一和一对多建模。ONE基数表示实现该接口的每个对象应链接到目标类型的一个对象。MANY基数表示实现该接口的每个对象可以链接到目标类型的任意数量对象。
您应根据本体论(Ontology)的建模需求来决定使用ONE还是MANY。在某些情况下,将链接的基数限制为单个对象可能更有意义。例如,您可能希望将Driver's License与Person之间的关系建模为SINGLE基数链接,因为每个驾照只能属于一个具体的个人。如果关系允许更大的灵活性,例如Company与其Shareholders之间的关系,您可能希望使用MANY基数链接,以表示每个公司可以有一个或多个具体的股东。