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

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

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

8.4.2 非重用方式

基于很多原因,代码重用的概念并不一定符合一些软件开发人员的期望。首先,很多情况下开发系统时甚至并未考虑重用。

其次,即使考虑到了重用,计划限制、有限的资源以及经费考虑等问题经常干扰最佳实践。

很多系统中代码与具体的应用程序高度耦合。这意味着该应用程序中的代码高度依赖同一个应用程序中的其他代码。

一些代码重用就是使用剪贴、复制和粘贴操作。在文本编辑器中打开一个应用程序,复制代码并粘贴到另一个应用程序中。有时无须任何修改某些函数或通用操作就可以使用。不幸的是虽然大部分代码无须调整,但小部分代码仍需要修改以适应具体的应用程序。

例如图8.6的UML图展示了两个独立的应用程序。

图8.6 发散路径的应用程序

本例中应用程序testDonutShop和testPizzaShop是完全独立的代码模块。这些代码可以保持独立,模块之间没有任何交互。然而这些应用程序可以使用一些通用的代码。事实上可能从一个程序复制整个代码到另一个程序中。该项目中的某人在某个时刻可能决定为这些在不同应用程序间共享的代码创建一个库。在很多运转良好且遵守纪律的项目中这种方式工作良好。编码标准、配置管理、变更管理等都会按照标准良好地运行。然而,在许多情况下,这一原则被打破了。

任何熟悉软件开发过程的人都知道,当产生缺陷且时间紧急的情况下,在系统中添加一些特定于当前处于困境中的应用程序的修复程序或添加程序,是很有诱惑力的。这可能只修复了出问题的应用程序中的问题,但可能对其他应用程序产生意想不到的、可能有害的影响。因此在这样的情况下,最初共享的代码会产生分歧,所以需要维护独立的代码库。 ...

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