7.1. Overview
EMF allows to define base models and extend them. The following will demonstrate this. It will also demonstrate how to work with EMF ecore models directly without using the ecore tools.
Create a new EMF project "sawan.modi.emf.inheritance". Create a new model by selecting File -> New -> "Eclipse Modeling Framework" -> "Ecore Model". Name the model "base.ecore".
Select "EPackage" as the basis and maintain the following properties for this package.
Right click on the package and select New Child -> EClass. Maintain the class "MyBaseClass" with two "EAttributes" of type "EString".
Create a new "Ecore" model "extendedmodel.ecore". Maintain "extended" as the package name. Right-click your model and select "Load resource".
Create a new class "MyExtendedClass" and press "ESuperType".
Add your "MyBaseClass".
Maintain a new EAtribute "detailedField" on "MyExtendedClass".
Create a new genmodel "extended.genmodel" based on extended.ecore. Generated Java code and you will see that the "MyExtendedClass" has extended "MyBaseClass".
0 comments:
Post a Comment