UML & SysML modelling languages

Expertise and blog articles on UML, SysML, and Enterprise Architect modelling tool

version francaiseTwitterVideos UMLChannel SparxSystems EA YouTubeLinkedIn
Tuesday, 20 August 2013 08:12

Enterprise Architect UML Patterns : define a set of elements to reuse on diagrams

Written by
Rate this item
(0 votes)

As an Enterprise Architect user, you may have had the need to apply several times more or less the same set of elements on a given diagram, leading to numerous uses of copy and paste as new.

The "copy and paste" feature on a selection of elements, including their associations and layout works ok, but there could be a more suitable way to go about this. Given a context where we have our set of elements i.e. a pattern of modelling elements available from one or several diagrams within our model, we need to apply them several times onto a new diagram. Once the new diagram is created, the elements that need to be duplicated aren't available from this blank diagram. Hence the diagram that contains those elements has got to be opened first, followed by a selection on the elements of interest, copied to the clipboard (Ctrl+C). Then the newly created diagram needs to be displayed again so the paste as new command can be executed (Ctrl+Maj+V). We also need to ensure that any specific element or information, e.g. an activity description or a child composite diagram and its sub-elements, mustn't be re-used, hence they need to be deleted.

Enterprise Architect makes it possible to re-use a set of elements, their associations, any notes, and their layout on the diagram by creating UML patterns. Similarly to the use of design patterns (GoF), the aim is to define a set of elements that can be applied for modelling purposes.

In the following example, a test case has been represented by modelling each step to follow as a node within a UML activity diagram, e.g. : pre-conditions / initial context, expected result, test result (OK/KO).

sparxsystems enterprise architect uml patterns with activity diagram

We can abstract these elements to be represented as re-usable steps, shown here :

sparx systems enterprise architect uml pattern

Once our pattern is defined in a standard diagram, such as the UML activity diagram above, we can save it into an Enterprise Architect UML pattern : open the Diagram menu > Advanced > Save UML Pattern, and save into a new XML file (e.g. C:\basic tests patterns.xml). Enable the "Merge" option if you need in some cases to merge a given activity (or another node) from your pattern with an existing activity from the target diagram (active diagram).

To import and have this pattern available from an EA project, open the Resources view (use the Project menu > Resources if this view is not displayed on your EA client), and right click onto UML patterns, choose "Import UML pattern", and browse to the UML pattern's XML file.

Your UML pattern is now available to use on your Enterprise Architect project ; it should be displayed within the list of UML Patterns. Simply drag and drop this pattern onto the current diagram to create a new test step with expected and test results, as defined in this UML pattern. This window lets you rename each element before it is created.

instanciate a uml pattern in enterprise architect

Of course UML patterns can be applied from any type of diagram (UML class, UML state machine, BPMN, SysML BDD, etc.) or model (analysis, design, tests, architecture, etc.).