# EMF Code Generation

EMF also ships with a code generator that generates Java classes from your Ecore model. The code generators input is the so called EMF generator model. It decorates (references) the Ecore model and adds additional information for the Ecore -> Java transformation. Xtext will automatically generate a generator model with reasonable defaults for all generated metamodels, and run the EMF code generator on them.

The generated classes are based on the EMF runtime library, which offers a lot of infrastructure and tools to work with your models, such as persistence, reflection, referential integrity, lazy loading etc.

Among other things, the code generator will generate

- A Java interface and a Java class for each EClassifier in your Ecore model. By default, all classes will implement the interface org.eclipse.emf.ecore.EObject, linking a lot of runtime functionality.

- A Java bean property for each EStructuralFeature (member variable, accessor methods)

- A package interface and class, holding singleton objects for all elements of your Ecore model, allowing reflection. EPackages are also registered to the EPackage.Registry to be usable at runtime.

- A factory interface and class for creating instances

- An abstract switch class implementing a visitor pattern to avoid if-instanceof cascades in your code.