Thursday, 23 January 2014

Week 3: Object-Oriented Programming

Up to now, 3 weeks have already slipped away unknowingly and a quarter of this semester just passed! But still, there's a long way to go. In the past 3 weeks, I was exposed to the idea of Object-Oriented Programming. As far as I am concerned, OOP is a really human-friendly way to convert real world objects to abstract data types. The concept of every object having their own attributes and methods is really natural for me, and I think, for most of you. But it was not always plain sailing, I found myself confused when first introduced to the term, 'inheritance'.  Once we declare a subclass,  it automatically inherits all the attributes and methods from the parent class. I do know how to modify or extend the code, but what if I want to cut off some attributes? For example, self.attribute = None? Hopefully, I can figure out this problem as I continue studying on Object-Oriented Programming. Last but not least, I also need your kind response!

1 comment:

  1. Hello,

    Regarding inheritance, I recommend you think about it in terms of sets. A class is a representation of a set of objects. E.g., class Human: {me, you, Biebs, ... etc}. When class B inherits from class A, it defines a subest. E.g. class CSC148_W14_Instructors {Danny, Dustin} (inherits from Human).
    In terms of "cutting off" attributes, this means that the further up you go in the inheritance hierarchy, the less information you should have (e.g. Human should not have an attribute "number_of_students", because only instructors have that). In other words, when you design a class inheritance hierarchy, you make sure that such "cutting off" does not happen (again, this sets and subsets).

    Cheers,

    Your friendly neighborhood TA.

    ReplyDelete