サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
Nintendo Direct
python-3-patterns-idioms-test.readthedocs.io
The Singleton¶ Possibly the simplest design pattern is the singleton, which is a way to provide one and only one object of a particular type. To accomplish this, you must take control of object creation out of the hands of the programmer. One convenient way to do this is to delegate to a single instance of a private nested inner class: # Singleton/SingletonPattern.py class OnlyOne: class __OnlyOne
Note This chapter is written using Python 2.6 syntax; it will be converted to Python 3 at a later date. Objects are created by other objects: special objects called “classes” that we can set up to spit out objects that are configured to our liking. Classes are just objects, and they can be modified the same way: >>> class Foo: pass ... >>> Foo.field = 42 >>> x = Foo() >>> x.field 42 >>> Foo.field2
© Copyright 2008, Creative Commons Attribution-Share Alike 3.0. Revision 59754c87cfb0.
このページを最初にブックマークしてみませんか?
『Python 3 Patterns, Recipes and Idioms — Python 3 Patterns, Recipes and Idioms』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く