Saturday, February 1, 2014

Inheritance and Exception (Week#4)

It has been a great week so far. This week, two important topics are introduced, inheritance and exception. We use inheritance to avoid rewriting some codes that have same characteristics. Professor Heap gave us an example on this topic. We have a parent class called Stack. It has its own methods such as push, pop, etc. And inheritance is introduced when a children class called IntStack is being created. Most of the methods are pretty much the same as its parent. We can create the children just by:

class IntStack(Stack)

and we can access the parent methods with Stack.method(...). This is really suitable for our first year goal - obtaining laziness. 

Another big big topic - exception, was 'raised' this week. We can create our own type of exception just by using inheritance:
XXXError(Exception)

We can raise one when something you don't want to see appears. However, when something wrong goes  into the program and you don't want the whole program to stop, an Try option can be built in the code. 

try:
    blah blah blah
except:
    blah blah blathe

The lab and exercise went pretty well and I hope I will start my assignment soon since it's busy these days.

Let's have a chat some time next week.

No comments:

Post a Comment