Last active
June 17, 2020 17:56
-
-
Save harshraj22/9d544b28499504f2bcfe9f7eb17d27a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# =====================Prob1===================== | |
''' | |
Given: | |
College Class (an Abstract class) | |
Person Class (an Abstract class) | |
To Implement: | |
Prof(Person): | |
IIT(College): | |
class College(ABC): | |
Follow ups: | |
* How will you ensure that two IITs with same name is not created ? If created, raise an exception | |
=> implement __eq__(self, other) | |
* How will you ensure not too many IITs are built ? | |
=> implement a __len__ method and have a class variable (number of active IITs) that increases on creating a instance | |
* How will your model be updated if some IITs are closed ? | |
=> implement a __del__ method that decreases the global count of number of active IITs | |
* why does first work but second fails ? | |
c1 = College('abc') | |
c2 = College('abc') | |
del c2 | |
c3 = College('abc') | |
c1 = College('abc') | |
c2 = College('abc') | |
l = [c1, c2] | |
del c2 | |
c3 = College('abc') | |
=> __del__ is called only if all reference to an object is removed, in second, even if del c2 is called, l[1] | |
refers to the object and so __del__ is not called | |
* How will your model updated if prof is allowed to teach more than 1 sub ? | |
''' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment