2015年2月16日星期一

Week 6

    Object-oriented programming includes many different parts, I will briefly explain something that I learnt like “class”, “method” “inheritance”. 

    Firstly, I would like to talk about “class”. If we talk about “Class” individually, “Class” is an extensive definition.  What particular “Class” define is what a particular group of items can do. And everything which fit this group can be executed by this “class”. Let’s assume that there is class called “PC”. Then, we can know that “PC” is a specific “object” for this class.   In addition, there are some different methods like “open PC”, “close PC”.  Briefly, this class called “PC” is set to execute every PC. Well, there are many different PC brands like Dell, Asus, and Lenovo. All of these various PC fit the class of “PC”, because they are PCs as we know.
    
    “Inheritance” is another interesting part. Sometimes, we could make a children class for a parent class. Let’s assume that there is a parent class called PC which can execute every PC like I mentioned in the last paragraph. Well, there is a children class called “laptop”. We just use some simple methods of python in order to call parent class in the children class. Now, children class has characteristics of parent class. The class “laptop” also can execute “open PC”, and “close PC”. However, the children class can be more specific than its parent class. For example, we may add one more method like “taking my laptop”. By the way, the method of “taking my laptop” is in the children class, the parent class cannot have or execute this method by itself.
    
    Generally, if children classes are executed, children still include functions of parent class. However, if parent classes are executed, children classes cannot do anything. I also read over one of my classmates’ blog (http://anniesslog.blogspot.ca/). She mentioned “NotImplementError”. This happens when a specific method, which is designed for a children class, appears in a parent class. If a parent class is executed individually, that method will not be executed. That method only can be executed when children class is being executing.

没有评论:

发表评论