Skip to Content
流畅的Python(第2版)
book

流畅的Python(第2版)

by Luciano Ramalho
April 2023
Intermediate to advanced
769 pages
25h 16m
Chinese
Posts & Telecom Press
Content preview from 流畅的Python(第2版)
261
10
使用一等函数实现设计模式
符合模式并不表示做得对。
——
Ralph Johnson
经典著作《设计模式》的作者之一
1
在软件工程中,
设计模式
指解决常见设计问题的一般性方案。阅读本章无须事先知道任何
设计模式。我会解释示例中用到的设计模式。
编程设计模式的使用通过
Erich
Gamma
Richard Helm
Ralph Johnson
John Vlissides
(“四人组”)合著的《设计模式》一书普及开来。该书涵盖
23
个模式
,通过
C++
代码定义
的类编排。不过,这些模式也可用于其他面向对象语言。
虽然设计模式与语言无关,但这并不意味着每一个模式都能在每一门语言中使用。例如,
读到第
17
章你会发现
,在
Python
中效仿迭代器模式毫无意义,因为该模式深植语言之中,
通过生成器即可使用。在
Python
中,迭代器模式无须“劳烦”类,实现代码也比典型方案少。
《设计模式》的作者在引言中承认,所用的语言决定了哪些模式可用。
程序设计语言的选择非常重要,它将影响人们理解问题的出发点。我们的设计模
式采用了
Smalltalk
C++
层的语言特性
,这个选择实际上决定了哪些机制可以
方便地实现,哪些则不能。如果采用过程式语言,那么可能就要包括诸如“继
承”“封装”和“多态”的设计模式。相应地,一些特殊的面向对象语言可以直
接支持我们的某些模式,例如,
CLOS
支持多方法概念
,这就减少了访问者等模
式的必要性。
1
出自
2014
11
15
Ralph Johnson
在圣保罗大学
IME/CCSL
所做的题为“
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

Python高级编程(第2版)

Python高级编程(第2版)

Posts & Telecom Press, Michał Jaworski, Tarek Ziadé
Python贝叶斯分析(第2版)

Python贝叶斯分析(第2版)

Posts & Telecom Press, Osvaldo Martin
高效能PYTHON程式設計

高效能PYTHON程式設計

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9787115612366