forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositionEx1.py
More file actions
33 lines (28 loc) · 931 Bytes
/
CompositionEx1.py
File metadata and controls
33 lines (28 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Repository:
''' Always initialize mutable attributes in the constructor '''
def __init__(self):
self.packages = {}
def add_package(self,package):
self.packages[package.name] = package
def remove_package(self,package):
if package.name in self.packages:
del self.packages[package.name]
def total_size(self):
res = 0
for package in self.packages.values():
res+=package.size
return res
class Package:
def __init__(self,name,size):
self.name = name
self.size = size
p1 = Package('src',1024)
p2 = Package('bin',512)
p3 = Package('resource',2044)
r = Repository()
r.add_package(p1)
r.add_package(p2)
r.add_package(p3)
print("Size of Repository After adding three packages in repository : ",r.total_size())
r.remove_package(p3)
print("Size of Repository After removing one packages in repository : ",r.total_size())