UML diagram: class diagram-detailed introduction

The concept of class diagram

A diagram describing classes, interfaces and their relationships, showing the static structure of each class in the system
Insert picture description here

Elements of the class diagram

class

  • The core of the object-oriented system organization structure
  • Abstraction of a group of objects with the same attributes, operations, relations and semantics
  • Including name part (Name), attribute part (Attribute) and operation part (Operation)

The composition of the class

  • name
  • Attributes
  • operating
    Insert picture description here

Name : It should be a noun, divided into a simple name and a path name. The first letter of each word is capitalized.
Attributes : describe the characteristics of the things (ie objects) represented by the class in the software system. The class can have any number of properties. It can also have no attributes

In UML, the syntax of class attributes is
Insert picture description here
attribute visibility

  • Public (Public) "+" All categories are visible
  • Private (Private) "-" This category and descendants can be seen
  • Protected "#" is only visible to the class itself
  • Package (Package) "~" is only visible to classes declared in the same package

Attribute name

  • Each attribute must have a name to distinguish it from other attributes in the class
  • The attribute name is composed of nouns or noun phrases that describe the characteristics of the class
  • Capitalize the first letter of all words except the first word

Attribute type: simple type, integer type, floating point type, boolean type, enumeration type,..., classes in the SDK, other custom classes in the system

The initial value of the attribute:
protect the integrity of the system, prevent missing values ​​or damage the integrity
of the system by illegal values, and provide users with ease of use

Operation
The abstraction of the transactions that the objects of the class can do.
A class can have any number of operations or no operations at all. The
return type, name, and parameters together are called the operation signature.
In UML, the syntax of the class operation is
Insert picture description here
the visibility of the operation:

  • Public (Public) "+"
  • Private (Private) "-"
  • Protected "#"
  • Package “~”

Operation name

  • Verbs or verb phrases used to describe the behavior of the category
  • The naming rules are the same as the attributes

Operational parameter table:

  • Some ordered attributes define the input of the operation
  • Is optional, that is, the operation does not necessarily have to have parameters
  • Definition method: "Name: Type"
  • If there are multiple parameters, separate each parameter with a comma
  • Parameters can have default values

Operation return type

  • Is optional, that is, the operation does not necessarily have a return type
  • Most programming languages ​​only support one return value
  • Specific programming languages ​​generally need to add a keyword void to indicate no return value

Interface
A description of the behavior of the object without giving the implementation and state of the object.
Contains operations but no attributes.
No associations visible to the outside world.
A class can implement one or more interfaces.
Insert picture description here

Relationship between classes

Dependency relationship
represents the semantic relationship between two or more model elements. The
customer depends on the provider in some form

Insert picture description here
Classification of dependencies:

  • Use dependency (Usage)
  • Abstraction
  • Authorization depends on (Permission)
  • Binding

Generalization relationship

  • The classification relationship between general elements and special elements
  • Can be used for classes, use cases, and other model elements
  • Describes a relationship of "is a kind of"

Insert picture description here
Association relationship
A structural relationship
that indicates the relationship between the objects of the thing.
Insert picture description here
The name of the association:
use a verb or verb phrase to name the association.
Clearly and concisely explain the relationship between the objects.
The name of the association is not necessary and
can be prefixed or suffixed to guide the reading direction. Direction indicator to eliminate ambiguity

Insert picture description here
Associated roles:
the responsibilities of one class to another in an association relationship.
The name of the role should be a noun or a noun phrase to explain how the object participates in the relationship.

Insert picture description here
Multiplicity of associations

  • Refers to how many objects can participate in the association
  • Can express a range of values, a specific value, an unrestricted range, or a set of discrete values
  • Format: "min… max" (all int type)
  • The multiplicity assigned to an endpoint indicates how many objects of the endpoint can be associated with an object of another endpoint
    Insert picture description here

Aggregation relationship
A special type of association
that represents the relationship between the whole and the part and
describes the relationship "has a"

Insert picture description here
Combination relationship
Combination is a special case of aggregation relationship. It is a stronger form of aggregation, also known as strong aggregation
. The life cycle of a member object depends on the life cycle of the
aggregation. The aggregation not only controls the behavior of the member object, but also controls the member object's behavior. Creation and destruction

Insert picture description here
Implementation relationship The relationship between the
specification (interface) and its implementation. The
customer must at least support all operations of the provider.
Both generalization and implementation can link the general description with the specific description.
Generalization connects the elements on the same semantic layer, and It is usually
implemented in the same model to connect elements in different semantic layers, and is usually built in different models
Insert picture description here
Insert picture description here

UML class diagram example

Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41784749/article/details/112250095