Skip to Content
面向对象的思考过程(原书第5版)
book

面向对象的思考过程(原书第5版)

by 马特 魏斯费尔德
August 2021
Intermediate to advanced
450 pages
4h 46m
Chinese
Pearson
Content preview from 面向对象的思考过程(原书第5版)

9.5 基数

在Object-Oriented Design in Java一书中,Gilbert和McCarty将基数表示为参与联合的对象个数,可以表示这种联合关系是可选的还是强制的。为了确定基数,Gilbert和McCarty提出了以下问题:

·对象之间是如何协作的?

·有多少对象参与协作?

·这种协作是可选的还是强制的?

例如,请看以下例子。我们创建了一个Employee类,其继承自Person类,并且和以下类有关系:

·Division

·JobDescription

·Spouse

·Child

这些类是用来做什么的?哪些是可选的?哪些是Employee类需要的?

·Division

 ·该对象包括了该雇员所在部门的相关信息。

 ·每名雇员都必须有部门,所以它们的关系是强制的。

 ·一名雇员只能隶属于一个部门。

·JobDescription

 ·该对象包括了工作简介,比如薪水等级以及薪水范围等信息。

 ·每名雇员必须有工作简介,所以它们的关系是强制的。

 ·雇员在公司工作期间可以有多个工作岗位。因此一名雇员可以有多个工作简介。如果雇员更改了工作岗位,但之前的工作内容仍需作为历史记录保存,而且一名雇员可以同时拥有两种不同的工作岗位。例如,管理员在某名雇员离职后还未找到替代者之前可以肩负起该雇员的职责。

·Spouse

 ·在这个极其简化的例子中,Spouse类只包括结婚周年纪念日信息。

 ·雇员可以是已婚也可以是未婚。因此,Spouse类是可选的。

 ·一名雇员最多只能有一个配偶。

·Child

 ·在这个简单的例子中,Child类只包含字符串FavoriteToy。

 ·雇员可能有孩子,也可能没有孩子。

 ·雇员可能没有孩子,也可能有无数个孩子(天哪)。你可以决定系统可以处理的孩子数量上限。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Node与Express开发(第2版)

Node与Express开发(第2版)

Ethan Brown
计算机科学导论:跨学科方法

计算机科学导论:跨学科方法

罗伯特 塞奇威克, 凯文 韦恩
手把手教会你linux

手把手教会你linux

桑德.范.乌格特
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉

Publisher Resources

ISBN: 9787111684527