3. Interfaces

Interfaces are present in Class, Component, Deployment, and Object diagrams. Poseidon allows you to choose a variety of ways to represent interfaces, the standard being the traditional box notation, which looks like a class with only two compartments (as attributes are not allowed in interfaces). They can also be drawn using lollipop (or ball) notation, and you can toggle back and forth between these two.

3.1. Box Notation

The box notation is just what is sounds like - the Interface is shown as a box with two compartments. The uppermost compartment contains the name, stereotype, and package information, while the bottom compartment displays operations that belong to the interface. The options available to an interface (such as hiding compartments) are identical to those available to classes.

To create a new interface with box notation, select the Interface button from the toolbar and click in the diagram.

You can toggle between box and lollipop notation using the representation rapid button.

3.2. Lollipop Notation

Lollipop notation is a condensed way to represent an interface. The interface itself is drawn as a circle with a solid line connecting it to another element. This indicates that the element to which it is connected 'offers' the interface.

In this example, the class Foo offers Bar as an interface.

You can create the class first and then add the interface using the lollipop rapid button.

Alternatively, you can create the interface with the 'Interface as Circle' toolbar button and connect it to the element by either dragging the lollipop rapid button from the element to the interface, or you can select the lollipop button from the toolbar and drag it from the element to the interface.

The order in which the elements are connected is important to the meaning of the diagram. If you drag the relationship from the interface to the element, you will create a 'realize' relationship, indicating that the interface realizes the element.

Using Interfaces with Ports

Interface elements are used slightly differently when they are presented in conjunction with ports; for instance, when an interface is connected to a port, it is not possible to directly open the interface properties by clicking on it in a diagram. You may only adjust the physical representation of the interface (move it around, resize it, etc.)

There are several ways to access the properties of the interface. You can select the port to which it is attached, and then double-click on the name of the interface in the Properties tab of the port, or you can select the interface from the Model Index view in the Navigation pane.

For details on how to add interfaces to ports and then how to delete them, see Section 3.3.2, “Adding an Interface to a Port” and Section 3.3.3, “Deleting an Interface from a Port”.

3.2.1. Sockets

In addition to the compact representations, lollipop notation has an advantage in the clarity of a diagram. This is because not only can 'provided' interfaces be modeled, but 'required' ones as well. These are called 'sockets' and are drawn with a semi-circle and line to the element requiring the interface.

To create a standalone socket that does not connect to a provided interface, you can either click the socket rapid button from an element, or you can click the socket button in the toolbar and drag it from an element to a blank space in the diagram.

To connect a socket to a provided interface, first create the provided interface as a circle. Then drag the socket rapid button (or socket toolbar button) from the element requiring the interface to the provided interface.

Here we see that class Foo offers the interface (Bar) that class Baz requires.

3.3. Ports

Ports provide a way to organize interactions between components and their environment within Component, Object, and Deployment diagrams. They can be uni-directional (only required or only provided interfaces connect to the port), or they can be bi-directional (both required and provided interfaces occur at one port).

Figure 12.9. Uni-Directional Port

Uni-Directional Port

By default, each port has a class as its type. The manner in which a port and its interfaces are rendered within Deployment, Object, or Component diagrams is derived directly from the relationship between the originating class and its interfaces. A realization will result in a provided interface; a dependency with the <<use>> stereotype indicates a required interface.

Below is an illustration of the same pair of interfaces in two different diagrams.

When a port is created in a diagram, a new class is automatically created semantically to function as the type for this port, although it is not added to the diagram. When interfaces are attached to this port, the interfaces are also semantically attached to the type class.

Try it Yourself - Add Ports and Interfaces
  1. Create a new Component diagram by clicking the 'New Component Diagram' button.

  2. Add a new Component by clicking the 'New Component' button and then clicking anywhere in the diagram.

  3. Add a port to this component by hovering over the component, then click the port rapid button.

  4. Click the 'Required Interface' button from the Details pane (below the Diagram pane).

  5. Verify that the selection 'Add Dependent Edges Automatically' checkbox is activated in Edit | Settings | Diagram Display.

  6. Create a new Class diagram by clicking the 'New Class Diagram' button.

  7. Drag the class called 'Port_Class' and the new interface into the diagram.

  8. Add a new interface and association by clicking hovering over the class, then clicking and dragging the realization icon to an empty space in the diagram.

  9. Return to the Component diagram. Notice that a new provided interface has been added here as well.

The properties of ports are very similar to those of other elements. The 'Port Properties' entry, however, only appears for ports. These checkboxes describe how the information entering the port will be handled.

  • isService - When checked, this port provides access to the published functionality of a classifier; when unchecked, this port implements the classifier but is not part of the functionality of the classifier, meaning that it can be altered or deleted.

    The default value is checked.

  • isBehavior - When checked, signal requests arriving at this port are received by the state machine of the object, rather than by any parts that this object contains.

    The default value is unchecked.

3.3.1. Adding a Port

To create a port on a component, first select the component in the Diagram pane, then click the port toolbar button in the Details pane (located under the Diagram pane). This is a bit different than with other element types. You cannot first select the tool from the toolbar and then apply it to the component.

A rapid button can also be used to create a port. Hover over the target component, then click the Port rapid button.

3.3.2. Adding an Interface to a Port

There are three basic ways to add an interface to a port, either through the main toolbar or through the Selection Bar (located between the Diagram and Details panes).

The simplest method is via the Selection Bar:

  1. Select the target port by clicking on it.

  2. In the Details pane (below the Diagram pane), click on either the 'Provided Interface' or 'Required Interface' button.

It is also possible to add an interface via the main toolbar:

  1. From the main toolbar, click on either the 'Provided Interface' or 'Required Interface' button.

  2. Click on the target port, then drag the mouse to an empty space in the diagram.

Existing and new interfaces can be added to a port from its Properties tab:

  1. To add an existing interface, open the dropdown list from either the 'Add Required Interface' or 'Add Provided Interface' text box and select the desired interface.

  2. To add a new interface, either type the new interface name in the text box or select '<New Interface>' from the dropdown list for an interface with a default name.

There is a fourth method using a Class diagram, which is more complicated and therefore not recommended in most situations. However, in limited cases it may prove useful:

  1. Select the target port by clicking on it. In the Properties tab, note the class indicated as the port type.

  2. If this class exists in an appropriate diagram, open that diagram. If not, create a new Class diagram and add the port type class.

  3. Add the new interface to the Class diagram by clicking the Interface button from the main toolbar, then clicking in the diagram.

  4. To make this interface a required interface, click on the 'Realization' button in the toolbar (or use the class rapid button) and drag from the port type class to the interface. The socket rapid button on the class may also be used to create the realization relationship - click on the socket rapid button from the class and drag it to the interface.

    To make this interface a provided interface, click on the 'Dependency' button in the toolbar and drag it from the class to the interface. Select this new dependency and click the ellipsis button to open the Stereotype dialog. Click on the stereotype 'use', click the '>>' button, then click 'Apply'. The lollipop rapid button on the class may also be used to create the dependency relationship - click on the lollipop rapid button from the class and drag it to the interface.

3.3.3. Deleting an Interface from a Port

Interfaces can be deleted from a port in a number of ways.

Delete from the Details pane:

  1. Select the port to which the interface is attached.

  2. Select the interface from the Properties tab of the port.

  3. Click the 'Delete' button from the toolbar that appears directly over the interface list.

    Alternatively, you can right-click on the interface name in the Properties tab and select 'Delete' from the context menu.

Delete from the Navigation pane:

  1. Locate the interface in the Navigation pane.

  2. Either right-click and select 'Delete' from the context menu, or click the 'Delete' button in the Selection Bar.

As noted in the previous section, the interfaces can also be represented in a Class diagram. Deleting the interface from the Class diagram will likewise remove it from any other diagrams in which it occurs.

You can also simply remove the element from the diagram without completely deleting the interface from the model:

  1. Select the interface from the Navigation pane to open the properties of the interface.

  2. From the Selection Bar, click the 'Remove from Diagram' button.