RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


UML for the Software Developer, Part 1: Building Classes : Page 2

Whatever language you code in, however you feel about documentation, and whichever process you ascribe to—you will need to model. Whether those models are in a formal charter, reference document, part of a diagram, or on the back of a napkin, you as a software developer will end up using models or modeling yourself.

Class Diagrams
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 clients—and 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 problem—char* 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.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date