11.2. Showing How a Class Is UsedThe 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:
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 capabilitiesIt'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.
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" interfacesFigure 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. |