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. Learning Puppet — Resource Ordering

    Learning Puppet — Resource Ordering Learn about dependencies and refresh events, manage the relation ...

  2. DHCP协议讲解

    一.DHCP服务介绍: DHCP为动态主机配置协议,该协议能自动配置主机的IP地址.子网掩码.网关及DNS服务器等TCP/IP信息.DHCP可以降低客户机IP地址配置的复杂度和网络管理成本. DHCP ...

  3. erlang使用leveldb

    用的是诺顿的开源库,参考url来自这里 下载 git clone git@github.com:/norton/lets.git 编译 cd lets ./rebar get-deps ./rebar ...

  4. 如何把python最小化安装在客户机上面

    因为想尝试在我们的桌面软件中加入python支持,所以想简化python的库,到时候直接放到客户机上面,并且放到我们的目录下,尽量免去不必要的东西,也不要影响机子,不过当写好的程序放到测试机子上后,老 ...

  5. encodeURIComponent编码后java后台的解码 (AJAX中文解决方案)

    encodeURIComponent编码后java后台的解码 (AJAX中文解决方案) 同学的毕业设计出现JavaScript用encodeURIComponentt编码后无法再后台解码的问题. 原来 ...

  6. 【转】SQL SERVER DateTime类型的精度

    先看下边的SQL 语句 CREATE TABLE #DateTest( Id INT, SampleDate DATETIME ) INSERT INTO #DateTest VALUES(1,'1 ...

  7. android 通知

    https://developer.android.com/design/patterns/notifications.html 通知系统可让用户随时了解应用中的相关和即时事件,例如来自好友的新聊天信 ...

  8. MODBUS-寄存器与功能码学习

    分类 简称 起始地址 结束地址 能够使用的功能码 输出逻辑线圈/(可读写位)/(DI/O)(如继电器开关控制) 0x 00000 09999 0x01读一组逻辑线圈 0x05写单个线圈 0x0f写多个 ...

  9. mysql 按年度、季度、月度、周、日SQL统计查询

    创建Table CREATE TABLE `test` ( `cdate` datetime DEFAULT NULL, `id` ) DEFAULT NULL, `name` ) DEFAULT N ...

  10. 20145305 《Java程序设计》第5周学习总结

    教材学习内容总结 1.设计错误对象都继承自java.lang.Throwable类 2.Throwable有两个子类:java.lang.Error与java.lang.Exception 3.Err ...