Python is a classical Object-Oriented Programming language. What are objects In Python? They can be Python built-in data types, such as strings, boolean, and list. They can also be “classes” that are created by programmers. Class can also contains various “methods” that perform corresponding jobs. Moreover, we can create subclasses that inherit the characteristics of the superclass and perform different jobs by adding methods. For example, we can create a class called “food” which is defined by the eatable characteristic. This means that subclasses of “food” such as “fruit”, “meat” and “vegetable” all shares the characteristic of being eatable.
In the lecture, Prof. Heap created a parent class called 'Shape', and two classes of 'Square' and 'Triangle' which inherit the variables of 'a' and 'b' from the 'Shape' class. One thing that I find important here is that the parent class raise an error when it is called to perform a function of its children.
def get_area(self): ''' (Shape) -> float Return the area of self. >>> from square import Square >>> Square(0, 0, 10).get_area() 100.0 ''' raise NotImplementedError('Need a subclass')
This is my basic understanding about what Object-oriented programming is. My classmate Christian has a deep understanding about the topic. Her writing of 'Week 6 Object-oriented programming concepts'(http://christiangarciacsc148.blogspot.ca/2015/02/object-oriented-programming.html) and 'Week 4 Classes and Subclasses'(http://christiangarciacsc148.blogspot.ca/2015/02/csc148-week-4-classes-and-subclasses.html) helped me a lot in understanding basic ideas of
Object-oriented programming as well as the purpose of this course.
No comments:
Post a Comment