SpecialistOff.NET
/ Вопросы
/ Статьи
/ Фрагменты кода
/ Резюме
/ Метки
/ Помощь
/ Файлы
Назад
Exercises
Метки:
python
- SingletonPattern.py always creates an object, even if it’s never used. Modify this program to use lazy initialization, so the singleton object is only created the first time that it is needed.
- Using SingletonPattern.py as a starting point, create a class that manages a fixed number of its own objects. Assume the objects are database connections and you only have a license to use a fixed quantity of these at any one time.
- Modify BorgSingleton.py so that it uses a class __new__( ) method.
Footnotes
[1] |
From the television show Star Trek: The Next Generation. The Borg are a hive-mind collective: “we are all one.” |
[2] |
From Dmitry Balabanov. |
[3] |
Suggested by Chih-Chung Chang. |