Class Diagram
A class diagram is a UML diagram that describes the structure of a domain or a system using entities, which are modeled as classes, along with relationships that exist between them.
Class diagrams are used for:
- high-level conceptual modeling (domain model)
- data modeling where they describe how the data are presented or stored in the system
- modeling objects that represent the actual internal design of object-oriented systems
The aim of this chapter is not to provide a comprehensive class diagram reference. Its goal is to introduce just the basics. Despite, from the analysis perspective, the basics should be sufficient in most cases, as long as the analysis does not include system design.
The class diagram above depicts:
- 4 classes representing 4 main entities managed by the system:
Order, Order Line, Product, Customer
- Class attributes that define data managed by each class. For example, the
Product
class is defined by the product name and its serial number, both being of a string data type.- As the class diagram could be just conceptual but could also include concrete implementation constructs, the same applies to data types. Domain models, for instance, could use abstract data types, such as
Address
orMoney
or no data types at all. Design classes, on the other hand, reflect the underlying technology and use real Java or C# data types.
- As the class diagram could be just conceptual but could also include concrete implementation constructs, the same applies to data types. Domain models, for instance, could use abstract data types, such as
- An enumeration - a data type, whose instances can be any of the predefined values
- Relationships that indicate logical connections between classes
- For instance, the
Customer
class is in relationship with theOrder
class expressing that a customer created one or more orders - More specifically, customer can have 0 or N (the * symbol) orders in the system, but each order belongs exclusively to one customer. This is called multiplicity.
- Another class diagram feature is navigability. It is indicated by the arrows on the edges of the relationship. It is possible to navigate from the
Customer
class to theOrder
class, which means that in the object-oriented application, it is possible to callCustomer.getOrders()
to look up all customer's orders. But it does not work from the other side, and instead of callingOrder.getCustomer()
, the developer needs to look up the customers by querying the database. TheCustomer
class includes a collection of the orders, but theOrder
does not include a reference to the customer who created it. Navigability is an advanced topic, though, not necessary for the needs of the Effective Analysis. - Note: All relationships in this diagram are modeled as associations. In order to be more specific about the semantic of each relationship, associations could be transformed into either aggregations or compositions. They are described in the separate chapter.
- For instance, the
What differentiates classes from plain data structures is that besides the data, classes also include operations for manipulating the data. For the sake of simplicity, they are not included in the provided diagram.