Class diagrams

In UML, class diagrams are one of six types of structural diagram. Class diagrams are fundamental to the object modeling process and model the static structure of a system. Depending on the complexity of a system, you can use a single class diagram to model an entire system, or you can use several class diagrams to model the components of a system.

Class diagrams are the blueprints of your system or subsystem. You can use class diagrams to model the objects that make up the system, to display the relationships between the objects, and to describe what those objects do and the services that they provide.

Class diagrams are useful in many stages of system design. In the analysis stage, a class diagram can help you to understand the requirements of your problem domain and to identify its components. In an object-oriented software project, the class diagrams that you create during the early stages of the project contain classes that often translate into actual software classes and objects when you write code. Later, you can refine your earlier analysis and conceptual models into class diagrams that show the specific parts of your system, user interfaces, logical implementations, and so on. Your class diagrams then become a snapshot that describes exactly how your system works, the relationships between system components at many levels, and how you plan to implement those components.

You can use class diagrams to visualize, specify, and document structural features in your models. For example, during the analysis and design phases of the development cycle, you can create class diagrams to perform the following functions:

During the implementation phase of a software development cycle, you can use class diagrams to convert your models into code and to convert your code into models.

The following figure is an example of a simple class diagram. This diagram shows how a class that represents a shopping cart relates to classes that represent customers, purchase orders, and items for sale.

A simple class diagram

The following topics describe model elements in class diagrams: