2.4. T03 Create a Constructor

In this tutorial we will create a simple constructor in a class with MetaFactory.

  • Open in directory metafactory-workshop-metafactory\src\patterns\package\feature1 the file called pattern1.xml and add the highlighted content to it:

Listing 2.9 src/patterns/package/feature1/pattern1.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<package xmlns="http://www.firstbase.nl/xsd/personaliom/pattern"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.firstbase.nl/xsd/personaliom/pattern http://www.firstbase.nl/xsd/personaliom/pattern.xsd"
         name="com.company.workshop"
         path="src/main/java">
  <class name="MyClass">
    <operation name="constructor">
      <body>// Constructor </body>
    </operation>
  </class>
</package>

Now:

  • Click on metafactory-workshop-metafactory in the MetaFactory Project window.

  • Click on the Play button to run the MetaFactory tool.

Once finished the MetaFactory Tool will have generated the Java class MyClass with the constructor in it.

  • Open metafactory-workshop-backend\src\main\java\com\company\workshop\MyClass.java to see the result.