UML basics - drawing graphic universe

[Two], UML basics

UML Overview

UML is a general purpose visual modeling language , a programming language is different from that used to model the system through some standard text and graphic symbols . It is used to describe software, visualization, structured document software system . It is a summary of the experience of the previous modeling techniques and to absorb the standard method for modeling the most outstanding achievements .

UML structure

view

  • User view : the user's point represent the target system, which is the core of all views, the view needs to describe the system.
  • Structural view : represents the static behavior of the system, the system described static element, such as a bag, and the relationship between the classes and objects thereof.
  • Behavioral view : that the constituent elements of the dynamic behavior of the system description of the system, such as the interactive relationship between objects in the system is running.
  • Implementation view : said relationship between them and the description of the file system in a distributed system of logic elements.
  • Environmental view : showing the relationship between the system they describe hardware and the distribution system of physical elements.

 

 

 

Map

  • Use Case Diagram
  • Class diagram , an object diagram, FIG package, the combination structure of FIG.
  • A state diagram, an activity diagram, a sequence diagram, communication diagram, a timing chart, an overview of FIG interaction
  • Component diagram
  • Deployment diagrams

Model elements

  • Model elements include the relationships between things and things and things
  • Things are an important part of the UML, it represents anything that can be defined
  • The relationship between things put things together to form meaningful structural model
  • Each element has a model with the corresponding graphic elements
  • A model with a different element can be used in the UML diagram
  • But no matter what the figure, the same model elements remain the same meanings and symbols

Universal Mechanism

  • It provides a general mechanism for UML model elements to provide additional comments, and other semantic information , including expansion mechanism , allowing the user to extend the UML.

Class A and FIG.

  • Class (Class) encapsulates the behavior and data , are an important part of object-oriented.
  • Class having the same attributes, operations, general term for a set of object relationships .
  • In the system, each class has a certain responsibility, responsibility refers to the class as a task of class to complete what kind of function, to assume what kind of obligations. A class can have a variety of responsibilities, a well-designed class is only one general duties .
  • I.e., the class and the attribute data functions , i.e., the operation of the class and the behavior of functions .
  • FIG class present in the system using different classes describe the static structure , which is used to describe the relationship between them and the different classes .

UML class icon

In UML class diagram, class generally consists of three parts:

  • The first part is the name of the class : Each class must have a name, class name is a string

In accordance with the naming conventions of the Java language class name first letter of each word are capitalized .

 

 

 

  • The second part is the attribute class : class attribute refers to a member variable nature, i.e. class. A class can have any number of attributes, the attribute may be omitted.

In accordance with the naming conventions of the Java language, property name in all lowercase the first word, after each word capitalized (hump nomenclature)

 

 

 

  • 第三部分是类的操作:操作是类的任意一个实例对象都拥有的行为,是类的成员方法。

按照Java语言的命名规范,属性名中的第一个单词全小写,之后每个单词首字母大写(驼峰命名法)

 

 

 

类之间的关系

关联关系

  • 关联关系是类与类之间最常用的一种关系,它是一种结构化关系,用于表示一类对象与另一类对象之间有联系。
  • 在UML类图中,用实线连接有关联关系的对象所对应的类,在使用Java、C++和C#等编程语言实现关联关系时,通常将一个类的对象作为另一个类的成员变量
  • 在使用类图表示关联关系时可以在关联线上标注角色名

 

 

 

  • 双向关联

 

 

 

  • 单向关联

 

 

 

  • 自关联

 

 

 

 

 

 

  • 多重性关联:多重性关联关系又称为重数性关联关系,表示两个关联对象在数量上的对应关系。在UML中,对象之间的多重性可以直接在关联直线上用一个数字或一个数字范围表示

 

 

 

 

 

 

  • 聚合关联
  • 聚合关系表示整体与部分的关系
  • 在聚合关系中,成员对象是整体对象的一部分,但是成员对象可以脱离整体对象独立存在
  • 在UML中,聚合关系用带空心菱形的直线表示

 

 

 

 

 

 

  • 组合关联
  • 组合关系也表示类之间整体和部分的关系,但是在组合关系中整体对象可以控制成员对象的生命周期,一旦整体对象不存在,成员对象也将不存在。
  • 成员对象与整体对象之间具有同生共死的关系。
  • 在UML中,组合关系用带实心菱形的直线表示

 

 

 

 

 

 

依赖关系

  • 依赖关系是一种使用关系,特定事物的改变有可能会影响到使用该事物的其他事物,在需要表示一个事物使用另一个事物时使用依赖关系。
  • 大多数情况下,依赖关系体现在某个类的方法使用另一个类的对象作为参数
  • 在UML中,依赖关系用带箭头的虚线表示,由依赖的一方指向被依赖的一方。

 

 

 

 

 

 

在系统实现阶段,依赖关系通常通过三种方式来实现

  • 将一个类的对象作为另一个类中方法的参数
  • 在一个类的方法中将另一个类的对象作为其局部变量
  • 在一个类的方法中调用另一个类的静态方法

泛化关系

  • 泛化关系也就是继承关系,用于描述父类与子类之间的关系,父类又称为基类或超类,子类又称为派生类。
  • 在UML中,泛化关系用带空心三角形的直线来表示
  • 在代码实现时,使用面向对象的继承机制来实现泛化关系,在**Java语言中使用extends关键字,在C++/C#中使用冒号":"**来实现。

 

 

 

 

 

 

接口与实现关系

  • 接口之间也可以有与类之间关系类似的继承关系依赖关系
  • 接口与类之间存在一种实现关系,在这种关系中,类实现了接口,类中的操作实现了接口中声明的操作
  • 在UML中,类与接口之间的实现关系用带空心三角形的虚线来表示

 

 

 

 

 

 

 

 

 

注释

 

 

 

实例——命令模式

 

 

 

公众号

能欣赏我的文章的话,可以顺便关注一下公众号,彼此欣赏,何必孤独:

 


作者:泰斗贤若如
链接:https://juejin.im/post/5e5656d26fb9a07ca137154b
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

发布了9 篇原创文章 · 获赞 5 · 访问量 791

Guess you like

Origin blog.csdn.net/weixin_45751082/article/details/104550083