Section 11.2. Showing How a Class Is Used


11.2. Showing How a Class Is Used

The internal structure of a class focuses on the contents of a class; ports focus on the outside of a class, showing how a class is used by other classes.

A port is a point of interaction between a class and the outside world. It represents a distinct way of using a class, usually by different types of clients. For example, a Wiki class could have two distinct uses:

  • Allowing users to view and edit the Wiki

  • Providing maintenance utilities to administrators who want to perform actions such as rolling back the Wiki if incorrect content is provided

Each distinct use of a class is represented with a port, drawn as a small rectangle on the boundary of the class, as shown in Figure 11-14. Write a name next to the port to show the purpose of the port.

Figure 11-14. A class with two ports showing that the class provides UserServices and Maintenance capabilities


It's common for classes to have interfaces associated with ports. You can use ports to group related interfaces to show the services available at that port.

Recall from Chapter 5 that a class can realize an interface, and this relationship can be shown using the ball interface symbol. When a class realizes an interface, the interface is called a provided interface of the class. A provided interface can be used by other classes to access the class through the interface.

Similarly, classes can have required interfaces. A required interface is an interface that the class requires to function. More precisely, the class needs another class or component that realizes that interface so it can do its job. A required interface is shown with an open lollipop, or the socket symbol.

Provided and required interfaces are used to promote loose coupling of classes and components. They are particularly important to components and so are discussed in more detail in component diagrams (see Chapter 12).


Suppose the Wiki class above implements the interfaces Updateable and Viewable, allowing other classes to update and view the Wiki through these interfaces. These interfaces are associated with the User Services port, so you can draw them extending out from the User Services port, as shown in Figure 11-15.

Figure 11-15. Ports can be used to group "like" interfaces


Figure 11-15 shows that the Maintenance port has a provided interface called Rollback, allowing administrators to roll back the Wiki. It additionally has a required interface called VersionControl, which is a service the Wiki uses for version control.




Learning UML 2.0
Learning UML 2.0
ISBN: 0596009828
EAN: 2147483647
Year: 2007
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net