|Figure 1. Brokerage Class: This first-iteration example class captures the base functionality needed for the application, but pools all the methods in one large Brokerage class.|
Class diagrams are usually the first diagrams taught for UML. They represent the static view of how classes interact. They are also the most familiar to software developers.
Class diagrams are composed of classes, and those classes represent the same functionality as classes in Java, C#, or C++. A box containing the class name, methods, and attributes represents each class.
In the following sections, you will be looking at a hypothetical brokerage business, RichMen Inc. RichMen is a very simple brokerage firm that has clientsand brokers buying and selling various securities for them. RichMen wanted a system to track which securities are bought and sold for each client, by each broker.
Iteration 1: The Brokerage Class
The first thing that we look at is how to store and retrieve securities, brokers, and clients. When we get to how the classes are related we will add buying and selling. For now we need to know the names of the securities, who the brokers are, and the firm's clients.
In Figure 1, we see our first iteration of the class. The top part of the box contains the name of the class, which in this case is simply Brokerage. Beneath the class name are the attributes of the class Brokers, Clients and Securities. A dash (-) precedes each attribute. This symbol signifies that the three attributes are all private to the class and not exposed to the outside world. After the attribute names we have a colon followed by char [1..*], which translates to an array of one-to-many strings where [1..*] is the multiplicity qualifier. The bottom of the box contains the different methods of the class: AddBroker, AddClient, AddSecurity, DeleteBroker, DeleteClient, DeleteSecurity, ListClients, ListBrokers, ListSecurities, and GetQuotes. The plus symbol (+) in front of each method tells us that each method is public and exposed to the outside world. After the method name you have the parameters, which are the same as expected if this were code followed by a colon and a return value. In the list methods there is one problemchar* in C is a pointer to some characters. What is needed is some way to point to many strings and not characters. Most modeling tools support types like string in UML, but in this case it's assumed that they don't.