This week, we reviewed what we have learnt about "class", and then, we further studied subclass and superclass. The reason for us to derived a new class from a base class instead of creating a new class directly is that programmers have a preference for inheritance. By inheriting, we can avoid writing the same code more than once. For a method in the subclass which has the same name as it does in superclass, we can use the same method as base class, we can also override and alter it. The readings on inheritance are supplement for lectures and they really helped me to further understand the meaning of using inheritance.
We also learnt about Exception. This is the most confusing part for me. Prof Heap encouraged us to try the examples by ourselves in order to better understand the material. After lecture, I played with the exception example, I tried all the possibilities listed in the example. I think I get some sense of it, but I still cannot explicitly explain why each result happens. So I decided to go through the reading on Exception. The reading provides me with more examples, but I am still a little confused. I tried python help() on except, there is a very long and detailed explanation for exception and it is really helpful. We often use try & except together. When python find a matching of excepting clause (the match may come from its super case, this is the tricky point.), the code inside except will be evaluated, otherwise, python will continue to go to the next except clause till the end.
In conclusion, this week's material is interesting but a little challenging for me. I am going to start exercise 2 soon, hopefully I will finish it this weekend :)
No comments:
Post a Comment