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. MSSQL 随机查询且降序排列

    --随机查询且降序排列 * FROM dbo.COMPANY_USER_INFO ORDER BY NEWID()) AS T ORDER BY T.cu_id DESC

  2. 共享内存是最快的一种IPC方式

    在linux进程间通信的方式中,共享内存是一种最快的IPC方式.因此,共享内存用于实现进程间大量的数据传输,共享内存的话,会在内存中单独开辟一段内存空间,这段内存空间有自己特有的数据结构,包括访问权限 ...

  3. 【Linux】系统 之 RAID

    本人从事DBA相关的工作,最近遇到了IO抖动伴随shread running抖动的情况,主机宕机重启后备库及下游解析binlog出现损坏的案例,向一些有经验的同事咨询学习,其中最大的嫌疑是:raid卡 ...

  4. 基于List集合映射

    1. 实体类中使用List集合 public class Grade { private int id; private String name; private List<Student> ...

  5. CE_现金的利息设定和计算(案例)

    2014-07-15 Created By BaoXinjian 一.摘要 存款利率指客户按照约定条件存入银行帐户的货币,一定时间内利息额同贷出金额即本金的利率.有活期利率和定期利率之分,有年/月/日 ...

  6. [ Iptables ] Linux开启防火墙,切记仔细确定每个端口

    一.缘由: 祸起Redis未授权访问漏洞被利用,删除了服务器的所有账号,导致无法登陆:这才不得不把开启防火墙提上日程.再次在开启防火墙过程中,一刀切造成了一些前段进程的端口被封,甚是后悔! 二.解决办 ...

  7. linux命令(5)文件操作:ls命令、显示文件总个数

    一:ls命令是最常用的linux命令了:下面是ls --help里面的用法 在提示符下输入ls --help ,屏幕会显示该命令的使用格式及参数信息: 先介绍一下ls命令的主要参数: -a 列出目录下 ...

  8. dynamic基元类型

    C#编译器允许将一个表达式的类型标记为dynamic.还可以将一个表达式的结果放到一个变量中,并将变量的类型标记为dynamic. 代码使用dynamic表达式/变量来调用一个成员是,编译器会生成特殊 ...

  9. ylbtech-dbs:ylbtech-7,welfareSystem(福利发放系统)

    ylbtech-dbs:ylbtech-7,welfareSystem(福利发放系统) -- =============================================-- Datab ...

  10. C++中为什么构造函数不能是虚函数,析构函数是虚函数

    一, 什么是虚函数? 简单地说,那些被virtual关键字修饰的成员函数,就是虚函数.虚函数的作用,用专业术语来解释就是实现多态性(Polymorphism),多态性是将接口与实现进行分离:用形象的语 ...