Author Dusty Phillips Reviewers



Download 2,95 Mb.
Pdf ko'rish
bet135/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   131   132   133   134   135   136   137   138   ...   183
Bog'liq
python3-oop

Manager objects
We've been focused on objects and their attributes and methods. Now, we'll take a 
look at designing higher-level objects: the kinds of objects that manage other objects. 
The objects that tie everything together.
The difference between these objects and most of the examples we've seen so far is 
that our examples tend to represent concrete ideas. Management objects are more 
like office managers; they don't do the actual "visible" work out on the floor, but 
without them, there would be no communication between departments and nobody 
would know what they are supposed to do (although, this can be true anyway if the 
organization is badly managed!). Analogously, the attributes on a management class 
tend to refer to other objects that do the "visible" work; the behaviors on such a class 
delegate to those other classes at the right time, and pass messages between them.
As an example, we'll write a program that does a find and replace action for text files 
stored in a compressed ZIP file. We'll need objects to represent the ZIP file and each 
individual text file (luckily, we don't have to write these classes, they're available in 
the Python standard library). The manager object will be responsible for ensuring 
three steps occur in order:
1. 
Unzipping the compressed file.
2. 
Performing the find and replace action.
3. 
Zipping up the new files.
The class is initialized with the 
.zip
filename and search and replace strings. We 
create a temporary directory to store the unzipped files in, so that the folder stays 
clean. The Python 3.4 
pathlib
library helps out with file and directory manipulation. 
We'll learn more about that in 
Chapter 8

Strings and Serialization
, but the interface 
should be pretty clear in the following example:
import sys
import shutil
import zipfile
www.it-ebooks.info


Chapter 5

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   131   132   133   134   135   136   137   138   ...   183




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish