Now, let’s start learning about class diagrams in UML:
Class diagrams are most commonly found diagrams while modeling software systems. A class diagram consists of classes, collaborations and interfaces. A class diagram is used to model the static design view of the system.
The class diagram shares the common properties with the rest of the diagrams, a name and graphical elements that are a projection into the model. What distinguish the class diagram from the others are the contents of the diagram.
Class diagram contains the following:
- Generalization, dependencies and associations
Like other diagrams, class diagrams may also contain notes and constraints. Class diagrams may also contain packages or subsystems which are used to organize the elements into groups. Generally, the class diagrams are used for:
- Modeling the vocabulary of the system
- Modeling the collaborations
- Modeling the logical database schema
Common Modeling Techniques
Modeling Simple Collaborations
To model simple collaborations,
- Identify the function or behavior of the part of a system you would like to model.
- For each function or mechanism identify the classes, interfaces, collaborations and relationships between them.
- Use scenarios (sequence of activities) to walk through these things. You may find new things or find that existing things are semantically wrong.
- Populate the things found in the above steps. For example, take a class and fill its responsibilities. Now, convert these responsibilities into attributes and operations.
Modeling a Logical Database Schema
To model a schema,
- Identify the classes whose state must be saved over the lifetime of the application.
- Create a class diagram and mark these classes as persistent by using tagged values.
- Provide the structural details for these classes like the attributes, associations with other classes and the multiplicity.
- Minimize the common patterns which complicate the physical database design like cyclic associations, one-to-one associations and n-ary associations.
- Provide the behavior for these classes by listing out the operations that are important for data access and integrity.
- Wherever possible, use tools to convert the logical design to physical design.
Forward and Reverse Engineering
To forward engineer a class diagram,
- Identify the rules for mapping the models to the implementation language of your choice.
- Depending on the semantics of the language, you may want to restrict the information in your UML models. For example, UML supports multiple inheritance. But some programming languages might not allow this.
- Use tagged values to specify the target language.
- Use tools to convert your models to code.
To reverse engineer the code,
- Identify the rules for mapping the implementation language to a model.
- Using a tool, navigate to the code that you want to reverse engineer. Use the tool to generate a new model.