UML (Unified Modeling Language) is a standardized notational system for diagramming the relationships between objects. It is designed to help organize programming code, particularly in object-oriented programming languages. It is a useful way to quickly diagram the various components of a code and their relationships to each other. It provides a bridge between the real world elements to be modeled and the logic of the computer code.
We will be using UML Class Diagrams as a way to organize our research and specify the relevant objects in the system we intend to model. Class diagrams describe the structure of objects to be modeled and their relationships to each other. Understood in its simplest form, it describes a taxonomy of objects. For instance, a taxonomy of animal “objects”:
The most important question when making a class diagram is: WHAT IS ESSENTIAL?
If we were interested in modeling cats, we might ask what is essential to the family felidae? What characteristics and behaviors are shared by all members of this family? When starting a Class Diagram, begin with the objects themselves, before considering any relationship between objects. An object has three types of components: Name, Attributes, and Operations. Attributes are the variables that define the characteristics of a class (size, color, id, etc.), operations are behaviors the class is capable of preforming (move(), eat(), addValue(), etc.).
The Tiger Class inherits all of the attributes and operations from the Felidae Class, adding additional attributes and operations that are essential and particular to the tiger. The class diagrams moves from the general to the specific by way of inheritance. Inheritance describes the parent-child relationship, and the passing of shared traits. The inheritance relationship is of the form ‘IS-A.’ a Tiger IS A Felidae.
When we define an attribute, we give it a name and a data type. For instance, the attribute “weight” is of data type “double” (a floating point number), and “numberStripes” is an “int” (an integer). So, weight could be 356.45, while number of stripes will always be a whole number, i.e 37. Common data types are:
- int: integer (1,2,3,4,5…)
- float: floating point number (4.5353)
- double: a more accurate kind of floating point number (5.23423545)
- character: one character of any kind (“a”, “6”, “%”)
- String: a list of characters (“hello world”, “5555”, “test123”)
- Boolean: true/false
- Other classes!!!
Data type #7 is a special case. Once you start defining attributes in one class as an object from another class, you introduce the second kind of relationship in Class Diagrams. This is called association. If inheritance is a ‘IS-A‘ relationship, association is a ‘HAS-A‘ relationship. In the example below, a person HAS A cup and a cup HAS A owner – The attribute “item” has data type “Cup”:
In the above diagram, you can start to see the power of inheritance. By defining the data type of “item” as the class “Cup”, we have established a relatively simple structure to allow the “person” to hold many different kinds of cups. Any child of Cup could be used in the attribute “item.” A person could hold a coffee cup or a plastic cup, or both, with all their particular characteristics and behaviors.
As you can see, a Class Diagram with only 4 classes already begins to describe fairly complex relationships. With this in mind, I would encourage you to start your diagrams small and work through the implications of their attributes, operations and data types. Make a separate class diagram for each of the objects with which you are working . Only start connecting them when an explicit inheritance or association relation will allow you to describe the system you are modeling with more clarity. It is much better to have a number of smaller diagrams that are fully worked out and legible then one big spaghetti diagram that nobody can understand.
Always, the question in your head should be WHAT IS ESSENTIAL? What is essential to your model, and what is essential to each class? Remove anything that does not have a specific, real, verifiable relationship to your model. The goal of UML diagramming is to find the simplest way to model complex situations.
There are many resources on the web for UML modeling. You can find more detailed information on the notation of class diagrams here. Some video tutorials for making class diagrams in the Astah UML modeler can be found here and here.