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.
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.
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”.
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.
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).
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|
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.
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.
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:
Select the target port by clicking on it.
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:
From the main toolbar, click on either the 'Provided Interface' or 'Required Interface' button.
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:
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.
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:
Select the target port by clicking on it. In the Properties tab, note the class indicated as the port type.
If this class exists in an appropriate diagram, open that diagram. If not, create a new Class diagram and add the port type class.
Add the new interface to the Class diagram by clicking the Interface button from the main toolbar, then clicking in the diagram.
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.
Interfaces can be deleted from a port in a number of ways.
Delete from the Details pane:
Select the port to which the interface is attached.
Select the interface from the Properties tab of the port.
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:
Locate the interface in the Navigation pane.
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:
Select the interface from the Navigation pane to open the properties of the interface.
From the Selection Bar, click the 'Remove from Diagram' button.