Skip to Content
Fluent Python ―Pythonicな思考とコーディング手法
book

Fluent Python ―Pythonicな思考とコーディング手法

by Luciano Ramalho, 豊沢 聡, 桑井 博之, 梶原 玲子
October 2017
Intermediate to advanced
832 pages
13h 34m
Japanese
O'Reilly Japan, Inc.
Content preview from Fluent Python ―Pythonicな思考とコーディング手法

12章継承の功罪

専門家だけが設計できるフレームワーク上で初心者でも作業できるようにするために、継承というアイデアを押し出し始めました。

——Alan Kay「The Early History of Smalltalk」より[EN-28]†1

[†1] 本章の執筆中にこの文献を教えてくれた友人のChristiano Andersonに感謝します。

本章では継承とサブクラス化を説明します。特に重点を置いているのは、次の2点のPython固有な話題です。

  • 組み込み型からサブクラス化するときの落とし穴
  • 多重継承とメソッド解決順序

多重継承は、その利点よりも欠点の方が多いと考える人もたくさんいます。Javaではなくても困りません。きっと、過剰な多重継承でトラウマになった人がC++で続出してしまったので、Javaはいろいろなところで採用されるようになったのでしょう。

反面、Javaの驚くべき成功と影響力のため、プログラマの多くは多重継承を現場で見ることなくPythonを使い始めることになります。そこで、本章では「おもちゃな例」は用いず、Tkinter GUIツールキットとDjangoウェブフレームワークという重要なPythonプロジェクトを例にとって多重継承を説明します†2

[†2] 監訳注:「おもちゃな例」(toy example)とは、本来はより複雑あるいは抽象化された問題を、それそのものではないけれども、噛み砕いた簡単な用例で示したものを指します。

では、組み込み型からのサブクラス化の問題から始めましょう。本章の残りの部分では、ケーススタディを通じて多重継承を説明し、クラス階層を構築するときのよい実践例と悪い実践例を考察します。

12.1 組み込み型からのサブクラス化には注意が必要 ...

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

Using Asyncio in Python

Using Asyncio in Python

Caleb Hattingh
Robust Python

Robust Python

Patrick Viafore

Publisher Resources

ISBN: 9784873118178Other