We want to show you a concrete example how to design a model, i.e., a UML Class Diagram, in Enterprise Architect (EA), with which you might generate C# code using the generic class concepts of .Net. In our case, a non-generic – concrete – class implements a “normal” class and a closed constructed interface.

The generated source code should look like this:

public class DummyScreenPresenter : BaseScreenPresenter, 
              IDummyScreenPresenter<DummyScreenPresenterNotification>

    {

    }

If you have already your source code, you might reverse engineer it with EA. The resulting model is correct, but not complete. So, the question arises how to define a model, with which the above code can be correctly generated using EA’s code generation templates.

1. Create the base class “DummyScreenPresenter”

2. Right click this class and define the implementations of the classes “BaseScreenPresenter” by selecting “Advanced -> Parent…”. For the implementation of “BaseScreenPresenter” this step sufficient, because in this case we do not want to have an own generated class.

clip_image001

3. Now we define the interface “IDummyScreenPresenter” and a corresponding template parameter. For this, we firstly create an interface from the toolbox. Double-click the class and select “Properties->Templates” to define a template parameter called “T”. After that, the interface should look like this:

clip_image003

4. Now, we need to model the actual type of the binding. In our case it is an enumeration called “DummyScreenPresenterNotification” also created via the toolbox. The model should look as depicted in the following figure:

clip_image004

5. For the correct binding, open the properties view of the base class “DummyScreenPresenter” and open the tap “Templates”. At the bottom of the view “Binding(s), we click on “Add->Realization” and select the right interface namely “IDummyScreenPresenter”

clip_image006

6. Another view is automatically opened. It is the properties view of the realization connection. Here, we can add the actual substitution of our defined template. Click on “Add” to create a new one. Select “T” in the column “Formal” and in the column “Actual” we select a Classifier. In our case, select the before created enumeration “DummyScreenPresenterNotification”. (Instead of choosing a classifier, you could also type a string value.)

clip_image007

7. Click on “OK” and that’s it! The model should look as follows:

clip_image008

When you now generate code for the class “DummyScreenPresenter”, the before presented excerpt is generated!