这正是 EMF 中“特征图”的用例。
您希望将多种类型的对象组合成一个有序列表,然后使用单独的引用访问各个类型。
所以,我创建了一个最小的元模型,它展示了 a 如何Document
包含Table
和Paragraph
实例的混合。

诀窍是所有实例实际上都位于elements
属性中(EFeatureMapEntry 数据类型)。然后,tables
和paragraphs
引用只是elements
容器的投影。如下图所示,实例以正确的顺序存储。

正确设置 EMF 类的所有属性有点棘手。尤其
volatile="true"
transient="true"
derived="true"
containment="true"
因此,我在这里列出了元模型的完整 XMI 内容:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="doc" nsURI="doc" nsPrefix="doc">
<eClassifiers xsi:type="ecore:EClass" name="Table">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Paragraph">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Document">
<eStructuralFeatures xsi:type="ecore:EReference" name="tables" ordered="false"
upperBound="-1" eType="#//Table" volatile="true" transient="true" derived="true"
containment="true">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="group" value="#elements"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="paragraphs" ordered="false"
upperBound="-1" eType="#//Paragraph" volatile="true" transient="true" derived="true"
containment="true">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="group" value="#elements"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="elements" upperBound="-1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="group"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>