Thursday, February 19, 2015

Week6-Object-Oriented Programming

Object-oriented programming is a method that represent real life systems and aims to solve real life problems. The name of Object-Oriented Programming is pretty self-explanatory. OOP is a type of programming that revolves around devising procedures by using a variety of independent and co-ordination objects. It also involves concepts such as class, objects, inheritance, instance, instantiation, message passing as so on.

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