UML类图

UML类图

1 . 简单说明-后面段落就不用看了。

这里写图片描述
这里写图片描述
这里写图片描述

2. class diagram 类图

A dass diagram describes the types of objects in the System and the various
kinds of static relationships that exist among them . Class diagrams also show
the properties and operations of a Class and the constraints that apply to the
way objects are connected . The UML uses the term feature as a general term
that covers properties and operations of a Class .
类图是描述系统中对象的类型以及各种不同的静态关系。类图也表示了属性和操作和对象之间关联的限制。uml使用术语特征(feature)作为一般的属于表示类的属性和操作。

3.类图
  • 对象的类型
  • 类的属性和操作
  • 对象与对象之间的静态关系
  • 对象连接的限制
3.1 basic concepts 基本概念
  1. Properties 属性==类中的字段。

    Properties represent structural features of a Class . As a first approximation, you
    can think of properties as corresponding to fields in a Class . The reality is rather
    involved, as we shall see, but that’s a reasonable place to start . 属性代表一个类的结构特点,最接近的说法是,你可以认为是类的字段。

  2. Attributes 特性=类中字段的具体描述。比public String field

 visibility name : type multiplicity = default {property-string} 
 下面是个简单的例子 : 
 - name : String [1] = " Untitled" {readOnly}
用java语言表示就是
private String[] name = new String["untitled"]; 并且不能有对name有写操作。
  1. Associations关联
    The other way to notate a property is as an association。
    另外一种使用图来表示特性的方法是使用关联。
    使用attribute表示类的属性-推荐使用
    使用关联表示类的属性
  2. Multiplicity 多样性 其实就是类中的字段。可能有0个、1个或多个对象。
    这里写图片描述

• 1 (An order must have exactly one customer .) 一个订单必须包含一个顾客。
• 0 . .1 (A corporate customer may or may not have a single sales rep .) 一个公司客户可能有也可能没有销售代表。
• (A customer need not place an Order and there is no upper limit to the
number of Orders a Customer may place-zero or more orders .)一个顾客不需要下订单,并且没有订单数量的上限,0个订单或者多个订单。

  1. Bidirectional Associations 双向关联 你中有我,我中有你。
  2. Operations 类中的函数
  3. Generalization 泛化就是类的继承
    With a software perspective, the obvious interpretation is inheritance : The
    Corporate Customer is a subclass of Customer . In mainstream OO languages,
    the subclass inherits all the features of the superclass and may override any
    superclass methods .
    以软件的角度来看, 泛化(generalization)最明显的解释是继承(inheritance):公司的顾客是顾客的子类,在主流的面向对象语言中,子类会继承所有父类的特征,并且可能覆盖任何父类的方法。
  4. Notes and Comments 笔记和注释
    9 . Dependency 依赖看作类的临时变量
    You may see these used with keywords «parameter», «local», and «global»
    参数。临时变量,全局变量,可以使用看作是依赖,比较弱的关联。
  5. Constraint Rules 限制条件 类中的限制说明
3.2 advanced concepts 先进的概念
  1. keywords

    One of the challenges of a graphical language is that you have to remember
    what the Symbols mean . With too many, users find it very difficult to remember what all the symbols mean . So the UML often tries to reduce the number of
    symbols and use keywords instead.An example of this is the interface {abstract},«interface»often gets abbreviated to «I» and {abstract} to {A}
    使用图形语言最大的挑战就是你不得不记住符号所代表的意义。太多的图形,使用者很难记住所有的符号代表的意义。所以uml尝试减少符号的数量。并且使用关键字代替。比如<<interface>>,<<abstract>>也可以缩写成<<I>>,<<A>>

  2. Static Operations and Attributes 静态操作和静态属性
    the UML refers to an operation or an attribute that applies to a dass rather
    than to an instance as static . This is equivalent to static members in C-based
    languages . Static features are underlined an a dass diagram (see Figure 5 .2) .
    uml中的操作或者属性如果是指在类上,而不是在实例对象上。称作为静态。和c语言中的静态成员变量是一样的。静态变量在类图中是以下划线表示。
    这里写图片描述

  3. Aggregation and Composition 聚合和组合
    Aggregation is the part-of relationship 。
    聚合是部分的关系。较强的关联,可以认为是类的成员变量。
    The “no sharing” rule is the key to composition
    组合的关键是不共享。假如你删除了三角形,那么组成三角形的点也跟着删除了。

  4. Interfaces and Abstract Classes 接口和抽象类。
    An abstract class is a class that cannot be directly instantiated . Instead, you
    instantiate an instance of a subclass . Typically, an abstract class has one or
    more operations that are abstract. An abstract operation has no implementation ; it is pure declaration so that clients can bind to the abstract dass .
    一个抽象类是是不能直接实例化的。反而你只能实例化抽象类的子类。通常一个抽象类有一个或多个抽象的方法。抽象的方法是没有实现的 。这是一个纯粹的声明以便使用者绑定抽象类。
    Classes have two kinds of relationships with interfaces : providing and requiring. A dass provides an interface if it is substitutable for the interface
    接口在类中有两种关系。提供和请求,一如果类可以替代接口,则类提供接口。
    A dass requires an interface if it needs an instance of that interface in order
    to work . Essentially, this is having a dependency an the interface .
    如果一个类需要一个接口的实例,它需要一个接口才能正常运行 。 从本质上讲,这是一个依赖关系的接口。
    这里写图片描述
3.3 When to Use Class Diagrams?什么时候使用类图 ?

Class diagrams are the backbone of the UML, so you will find yourself using
them all the time .The trouble with class diagrams is that they are so rich, they can be overwhelming to use . Here are a few tips .
类图是uml的主要组件,你会发现你经常使用它,但麻烦的是类图有很丰富的组件。他们可能会被过度使用。下面是一些小建议。

  1. Don’t try to use all the notations available to you .
    不要尝试使用所有的符号.
  2. I’ve found conceptual class diagrams very useful in exploring the language
    of a business . For this to work, you have to work hard an keeping software out of the discussion and keeping the notation very simple .
    我发现概念性的类图在探索成为商业的一种语言很有用。我们应该保持在讨论之外,保持使用的符号很简单。
  3. Don’t draw models for everything ; instead, concentrate an the key areas . It
    is better to have a few diagrams that you use and keep up to date than to
    have many forgotten, obsolete models .
    不要为所有的事物建立模型。相反,关注关键区域,与其拥有很多已经被遗忘的、过时的模型,还不如定时更新一些你使用的类图。

参考:
1. uml distilled
2. http://www.uml.org.cn/oobject/201104212.asp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值