+ 1
Is this code well made? Good enough? Anything to improve?
4 ответов
0
Your setter 'set_cage' is here totally useless, so you should remove it.
Since all is public in Python, we only define getters and setters (with 'property') when it is worth creating them.
Here, in your code, it brings nothing, so you should remove your method 'set_cage' and use the 'cage' attribute directly.
0
Théophile ok, thanks. And about the classmethod: is what I did correct? The part when I used the class method in the constructor (__init__) ?
0
I think it is relevant to use a classmethod in that case, so yes, I find it correct.
However, I had named the class method '_add_animal' instead of 'add_animal'. The reason is that this method should be considered as a private method (I'm not sure that you want a user to call this method from outside your class ;) ).
!warning! It will not make your method effectively private, but the user will have to consider it as private.
Regarding the '__init__' method, I have only one thing to say : rename the parameter 'type'. Indeed, the name 'type' is the name of a built-in function, so it is better not to shadow it!
Anyway, good job! 👍
0
Théophile Thanks! 👌🏻