Article Consultation Solution Tool Course Member  
 
 
 
     
   
 Subscribe
UML Diagram: Class Diagram
 
Zu Tao ,Pitaya System Engineering
Views    2020-2-13
 

 

Why do you need class diagram modeling?

Class diagrams are the crystallization of object-oriented thinking, which describes things in the objective world from the perspective of objects:

  • An object is an objective world being that occupies space // such as a wheel
  • External performance characteristics // e.g. radius of wheels
  • It interacts with the outside
  • An object may be made up of smaller objects, like molecules with atoms inside them;
  • One object may have a link to another
  • ... ...

There are many objects in the real world, and in order to describe them concisely and make it easier to communicate, people abstract several similar objects into classes:

  • Classes exist only in the human mind, in the human language,,
  • Give the class a name that reflects the instance of the object it represents
  • Describe the characteristics of an object with attributes
  • Methods describe the behavior of an object
  • A class of a partial object can make up a class of an entire object
  • A class can be associated with another class
  • Several similar classes can be abstracted as parent classes
  • ... ...

The relationships between objects are abstracted into the relationships of classes: association, aggregation, composition, generalization, implementation, and so on.

It's a bit abstract to say, for example.

 

When we are faced with complex logical descriptions, the process of reading is actually the process of understanding various concepts and relationships, and object-oriented analysis methods and class diagrams can greatly improve the efficiency and accuracy of understanding.

The following is a functional description of a motor control system, which the engineer described in text language as follows:

Description of the function
The operator issues control commands to the controller, which starts the motor
  • If the conditions are met, the motor starts up with a success message to the operator
  • If the conditions are not met, a warning message is fed back to the operator
There are two types of motors, DC motors and AC motors, and the starting conditions for voltage determination are different
  • If the DC motor, the voltage reaches 100 volts to start
  • If the AC motor, the voltage reaches 200 volts to start

 

If the relevant concepts are modeled with a class diagram, the model is as follows:

Which is better?

  • Easier to understand
  • More comprehensive
  • It is easier for developers to translate into system implementations.

I guess readers can judge for themselves based on their intuition!

 

What is there in the class diagram

Any UML diagram has semantics, elements, relationships, and uses, and the following is a list of class diagrams:

Semanteme Describe the class, its properties and methods, and the relationships between the classes
Element Kind (class), interface, abstract class
Relationship Relationships between classes:
  • Association-association, aggregation-aggregation, composition-compose
  • Dependency-dependency
  • Generalize-generalize
Relationship between classes and interfaces:
  • Realization
Use Classify objects in the objective world, describe features with attributes, describe behaviors with methods, and model the relationship between classes to help users:
  • Conceptual modeling
  • Data modeling
  • Design class modeling
  • Implement class modeling

 

Legend: Domain model

The class diagram can be used to perform object-oriented analysis of the problem domain, analyze the properties, methods, and relationships of various domain objects, and establish a domain model (also called an analytical model), as shown in a simplified example of a domain model:

 

Legend: Design modelsnake game class diagram

In order to make the reader look more vivid, the use of legends to introduce the use of class diagrams, the following is the design class diagram of the snake game. The difference between the design class diagram and the analysis class diagram is that the software implementation environment of the computer and the development language mechanism are considered, and a logical view of the solution is given from the development perspective:

 

In order to achieve software robustness, design class diagrams often use design principles, such as the following:

  • Based on the principle of single responsibility, Map and Food are separated.
  • Based on the principle of interface isolation, the interface Movable is abstracted.
  • Based on the principle of dependency inversion, the interface Movable is placed on the same layer as the Map.

Class Diagram Description:

The following is a description dictionary of a class generated from a class diagram:

Serial number  Kind   Illustrate
 1.  Timer The timer class has a method tick, and when the time is up, the whole method is triggered - the mobilization object Move().
 2.  Map Map class, with attributes weight, height, color, cellSize; Has the method CreateFood().
 3.  Movable
An interface that can represent a movable object, with the method declaration Move().
 4.  Animal The animal class is an abstract class with attributes Length and integrals, with the abstract method Move().
 5.  Node Node class, with properties pointX, pointY, size, color; Has the method Draw().
 6.  Food The food class has the attributes name and score.
 7.  Alligator
Crocodile, with the property food and method move(), inherits the Animal class.
 8.  Snake Snakes, with the method Move(), inherit from the Animal class.
 9.  Train Train class, with method Move().
 10.  Direction Directional enumeration type, with values up, down, right, left.
 11.  Color Color enumeration type with multiple colors: Red, Green, Blue, Orange, Black.

The following is a directory of relationships between classes generated from the class diagram:

 Serial number  Start class  Relationship Endpoint class
 1.  Map  Association  Movable
 2.  Direction  Aggregation  Movable
 3.  Animal  Realisation  Movable
 4.  Node  Aggregation  Animal
 5.  Food  Generalization  Node
 6.  Node  Aggregation  Map
 7.  Train  Realisation  Movable
 8.  Timer  Dependency  Movable
 9.  Alligator  Generalization  Animal
 10.  Snake  Generalization  Animal
 11.  Node  Association  Color

You can generate code based on class diagrams, as follows the code generated based on class diagrams (C++ language)

 

You can generate a data model based on a class diagram and then generate DDL code based on the data model. Here's the data model generated from the class diagram:


DDL code can be generated based on the data model, as follows:

 

Note: The model in this paper uses the modeling tool EA to model, generate code, and generate database.

 

 


UML Diagram Series:

1.UML Overview
2.Use Case Diagram
3.Activity Diagram
4.Class Diagram
5.Object Diagram
6.Sequence Diagram
7.Interpretation of the Mapping Relationship between Class Diagram and Code (C++)

 

Postscript

I hope you have benefited from reading this.

If you are willing to share your experience, please submit it to us.

If you are interested in our training, consulting and tools:

  • Course: Analytical design based on UML and EA  
  • Course: MBSE (Model-Based Systems Engineering)  
  • Course: Model-Based Requirements Management) Methods and Practices
  • Course: System Design and Modeling Based on SysML and EA
  • Course: Enterprise Architecture Modeling
  • Course: System Architecture Modeling Methods and Cases
  • Course: Domain-Driven Modeling and Design
  • Course: Model-Based Design
  • Course: Business Modeling and Business Analysis
  • Modeling tool: EA
  • Model-based requirements management tool: iSpace
  • Consulting Solution: MBSE (Model-Based Systems Engineering)
  • Consulting Solution: Model-Driven Development Based on UML
  • Welcome to contact us: umlooo@hotmail.com

       
    Views  
     
    Related Articles

    UML Overview
    UML Diagram: Use Case Diagram
    UML Diagram: Activity Diagram
    UML diagram: class diagram
    UML Diagram: Object Diagram
    UML Diagram: sequence diagram
     
    Related Courses

    MBSE (Model-based Systems Engineering)
    System analysis and design based on UML
    Business Modeling & Business Analysis
    System design and modeling SysML EA
    Model-based requirements management
    Business Modeling &; Domain-Driven
     
    Related Tool

    MBSE Platform
    Modeling Tools EA
    Requirements Management
    Automatic modeling
    Multi-level simulation -Sys Simulator
    Code Engineer

    Tool News
    June 2024 EA v17.0 Beta release
    November 2022 EA v16.1 release notes
    November 2022 EA v16.1 official release
    July 2022 EA v16.05 release notes
    April 2022 EA16.0 official release
     
    Latest Article
    UML Overview
    UML Diagram: Use Case Diagram
    UML Diagram: Activity Diagram
    UML diagram: class diagram
    UML Diagram: Object Diagram
    UML Diagram: sequence diagram
    Specification changes from UML 2.4 to UML 2.5
    DDS models and modeling tools
    More...   
    MBSE Tool
    MBSE Platform
    Modeling Tools EA
    Requirements Management
    Automatic modeling
    Multi-level simulation -Sys Simulator
    Code Engineer
    DocGenerator
    Model Checker
    R&D management
    TestDriver
    Model Based Quality Manager (inspector)
    More...   
    Successful Case
    Gac Research Institute SysML+EA+ Software
    Modeling tools EA, WebEA, and learning
    China Automotive Intelligence modeling tools EA...
    Ekatong MBSE tool chain consulting
    Avic UAV MBSE tool chain
    Geely Auto buys EA tools
    Huaco Auto parts buy EA tools
    Dongfeng LAN Map Auto purchase EA tools