2015年2月16日星期一

Week 6   Summary of Object-Oriented Programming Concepts

   
This week we were asked to write self-summary of Object-Oriented Programming, which is a quite abstract concept for me. And professor also only mentioned once about its meaning in the lecture. Hence, I searched on the Internet and looked through other classmates’ slogs to learn.

l   Brief definition

According to Wikipedia, “Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods.” (From http://en.wikipedia.org/wiki/Object-oriented_programming)
   
I take “hand” as an example to understand this design philosophy ---- Object-oriented programming (OOP). Your body has two object of the type “hand”, called “left hand” and ”right hand”. Your shoulders send a set of electrical signals to control your “left hand” and ”right hand”. Therefore, the shoulder is an “interface” that your body uses to interact with your hands. In this case, the ”hand” can be seen as a “class”, and is being reused to create the left hand and the right hand by slightly changing the properties of it.
 

·         Object

An “object” can be considered as a “thing”, which can perform lots of performance. In the case above, the “hand” is the object, and it can applaud or grab something. As for the example in the lecture, employee is the object, and he/she can calculate his/her salaries.


·         Abstract Data Types

An “object” can be int, str, list and dict, and these are called Abstract Data Types, or “ADTs” for short.
   
The typical Abstract Data Types are stacks, queues, dictionaries and so on.

1) Stacks (First in, last out)
Built-in functions:
Push: Add an item on to the top of the stack
Pop: Removed an item from the top of the stack.
Size: The number of elements.
is_empty: Return whether this Stack is empty
   
2) Queues (First in, first out)
Built-in functions:
Push: Add an item at the end of the queue
Pop: Removed an item from the beginning of the queue.
Size: The number of elements.
is_empty: Return whether this Stack is empty

These two ADTs are quite similar. The major difference between them is the order how they pop/remove an element. For stacks, the first item added is the last one to be removed, whereas, for queue, The first item added is the last one to be removed.

·         Class


A class is simply a representation of a type of object. It shows the details of the object, just like a blueprint. A class employee has all this employee’s relative attribute(information): name, ID number, social insurance number and pay period.

·         Special methods



·         Inheritance

    Inheritance is an object-oriented programming feature whose purpose is to shorten the amount of code being used overall when writing multiple classes similar to one another in some way.
    If the child class needs the same method from its parent class, we do not need to “override” the method again, just inherit from parent class.

The framework is like:
def __init__(self, subclass_parameter):
   ParentClass.__init__(self, class_parameters)
   self.new_name = subclass_parameter

In method __init__, we just add new parameters for subclass after self. But we have to write the second line as above to label the inheritance. 


l   Reaction to classmates’ slogs

1)   http://computersciencemaggie.blogspot.ca/2015/03/summary-of-object-oriented-programming.html?showComment=1428298896513 
Detailed and logic explanation
Excellent slog to comprehend the concept of ADTs
Boyang Wu’s slog helped me understand better, because he wrote this summary combined with lectures’ and assignments’ examples. This made more sense to me, and help me draw a clear picture of ADTs.


l   Study material I found:

1) Introduction to Object Oriented Programming Concepts (OOP) and More:
2) Wikipedia:


没有评论:

发表评论