File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
section16/sample_code/4-abc-3-and-interfaces Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1
1
from database import Database
2
2
from admin import Admin
3
+ from user import User
4
+ from saveable import Saveable
3
5
4
6
a = Admin ('paco' , 'perez' , 2 )
5
7
b = Admin ('rolf' , 'smith' , 1 )
9
11
10
12
user = Database .find (lambda x : x ['username' ] == 'paco' )[0 ]
11
13
user_obj = Admin (** user )
12
- print (user_obj .username )
14
+ print (user_obj .username )
15
+
16
+ print (isinstance (user_obj , Saveable )) # This is True because it's a subclass
17
+
18
+ # You can do things like these without worry:
19
+
20
+ users_to_save = [a , b , User ('jose' , '1234' )]
21
+ for u in users_to_save :
22
+ u .save () # This is fine, because all users (Admin and User) implement the Saveable interface so we know they have a .save() method
You can’t perform that action at this time.
0 commit comments