So far we have seen stack diagrams, which show the state of a program, and object diagrams, which show the attributes of an object and their values. These diagrams represent a snapshot in the execution of a program, so they change as the program runs. They are also highly detailed, and for some applications, too detailed. A class diagrams is a more abstract representation of the structure of a program. Instead of showing individual objects, it shows classes and the relationships between them.

There are several kinds of relationship between classes:

  • Objects in one class might contain references to objects in another class. For example, each Rectangle contains a reference to a Point, and each Deck contains references to many Cards. This kind of relationship is called HAS-A, as in, ‘a Rectangle has a Point.’
  • One class might inherit from another. This relationship is called IS-A, as in, ‘a Hand is a kind of a Deck.’
  • Once class might depend on another in the sense that changes in one class would require changes in the other.

A class diagram is graphical representation of these relationships between classes. For example, this diagram shows the relationship between Card, Deck and Hand.

The arrow with a hollow triangle head represents an IS-A relationship; in this case it indicates that Hand inherits from Deck. The standard arrow head represents a HAS-A relationship; in this case a Deck has references to Card objects. The star(*) near the arrow head is a multiplicity; it indicates how many Cards a Deck has. A multiplicity can be a simple number, like 52, a range, like 5..7 or a star, which indicates that a Deck can have any number of Cards.

from Thinking in Python

Class diagrams的更多相关文章

  1. EF:split your EDMX file into multiple diagrams

    我们可以把一个EDMX文件划分为多个类图: 1.在VS中打开EDMX设计器: 2.切换到“模型浏览器”属性设置窗口: 3.在diagrams上右键菜单中选择“添加新的关系图”: 4.在原来的关系图上可 ...

  2. How to generate UML Diagrams from Java code in Eclipse

    UML diagrams compliment inline documentation ( javadoc ) and allow to better explore / understand a ...

  3. codeforces Diagrams & Tableaux1 (状压DP)

    http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...

  4. (转) Deep learning architecture diagrams

    FastML Machine learning made easy RSS Home Contents Popular Links Backgrounds About Deep learning ar ...

  5. [RxJS] Marble diagrams in ASCII form

    There are many operators available, and in order to understand them we need to have a simple way of ...

  6. 条形图(diagrams)

    条形图(diagrams) 题目描述 小 虎刚上了幼儿园,老师让他做一个家庭作业:首先画3行格子,第一行有3个格子,第二行有2个格子,第三行有3个格子.每行的格子从左到右可以放棋子,但要 求除第一行外 ...

  7. Generating Sankey Diagrams from rCharts

    A couple of weeks or so ago, I picked up an inlink from an OCLC blog post about Visualizing Network ...

  8. Reliability diagrams

    Reliability diagrams (Hartmann et al. 2002) are simply graphs of the Observed frequency of an event ...

  9. Characterization of Dynkin diagrams

    Nowadays, I am reading D.J.Benson's nice book, volume I of Representations and cohomology. I found i ...

随机推荐

  1. 关于snprintf的一个warning

    在编一段代码时用到snprintf,有个很奇怪的warning 编译提示: warning C4013: 'snprintf' undefined; assuming extern returning ...

  2. 重新定位svn地址的方法(windows和linux),svn switch(sw)的帮助信息

    今天公司的路由器出现问题,服务器的IP地址也跟着变了,但是原来的svn已经设置好了,现在需要更换地址 查询原地址的方法: root@jack-desktop:codes# svn info 路径: . ...

  3. 导航栏4种效果---原生js

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  4. XML封装与验证消息

    Document document = DocumentHelper.createDocument(); document.setXMLEncoding(ChARSET_UTF_8); Element ...

  5. BIP_开发案例01_BI Publisher报表手工提交和控制(案例)

    2014-12-27 Created By BaoXinjian

  6. HUST 1010 The Minimum Length(KMP,最短循环节点,即i-Next[i])

    题意: 有一个字符串A,假设A是“abcdefg”,  由A可以重复组成无线长度的AAAAAAA,即“abcdefgabcdefgabcdefg.....”. 从其中截取一段“abcdefgabcde ...

  7. MVC项目发布错误

    下面各个方法尝试采用: 重装Framework 32位的Windows: --------------------------------------------------------------- ...

  8. C++程序设计原理与实践

    std_lib_facilities.h和VS下创建C++程序方法:下载 目录: 001. Hello,World!

  9. nginx重写规则报nginx: [emerg] directive "rewrite" is not terminated by ";"

    对于下面的重写规则 rewrite ^/gongying/([\d]{8})_([\d]+).html$ /index.php?app=support&act=view&pts=$1& ...

  10. 转--Android资源总结(环境搭建/ 反编译工具)

    在Android发展前景相当好的情况下,本人最近搜集了一些关于Android的相关资源,当然包含以前发布的博客内容,进行了一次大整合,希望对和我一样是Android的初学者管用,如在文章中有所错误,敬 ...