Friday, February 13, 2015

Summary of Object-Oriented Programming Concepts

Concepts of Object-Oriented Programming

Object-Oriented Programming (OOP)

OOP is a programming paradigm that is based on objects, rather than other things, like imperative, declarative.

Object

Object is an instance of a class.

Class

Class is a combination of attributes and methods. It can be pre-defined, or can be written by the programmer.

Subclass

Subclass is a secondary class under the superclass. It inherits all the attributes and methods of the superclass. It can also build it own attributes and methods by overriding the original one.

Upperclass

Upperclass is the parent class of a subclass.

Inheritance

Inheritance (verb: to inherit) means that the subclass can possess all the attributes and methods the superclass have.

Overriding

Overriding (verb: to override) means that the subclass can override some attributes or methods inherited from the upperclass.

Attribute

Attribute defines the property of a class. In python, it is defined in __init__ and attributes are often inserted by parameters.

Initialization in a Class (__init__)

Initialization (verb: to initialize) is where we define the attributes and parameter of a class. It must be defined in a class. In python, it is defined by "__init__" in python.

Self

Self represents the class itself inside a class.

Parameter

Parameter means the variable taken by a class. Parameters always become attributes when initializing.

Argument

Argument is the specific parameter in a class.

String in a Class (__str__)

__str__ returns a string that contains the public face of the class.

Representation in a Class (__repr__)

__repr__ returns a string that contains the exact representation of the class. Sometimes it is same as __str__.

Equivalence in a Class (__eq__)

__eq__ compares whether 2 objects are equal and therefore returns a boolean.

Abstract Data Type (ADT)

ADT is a kind of data type that is abstract.

Recursion

If a function uses itself in the function, then it uses recursion.

Stack

Stack is a class that users can only reach the top of the stack (the last item of the list).

Tree

Tree is a class that has its value and children.

Saturday, February 7, 2015

Mystery Solved: Impressions of Tracing Recursion in week 4

Debutant of Recursion

Although the two assignments of computer science had really messed me up, I became even more stressful at the Monday class of the 4th week. The first thought of recursion was that I was not suitable for learning computer science. I was about to drop the course or even change my major. Though it was a little bit exaggerated, you could still imagine how I felt about it. Recursion was something completely incomprehensible at the first glace. 

Panacea

However, with the introduction of the concept of recursion, the professor had also kindly provided us a piece of sheet for the first time. He started to explain the details, that is, tracing recursion. I began to understand more of recursion, and get confused, and understand more, and get confused, and so on... Wow, how amazing it is!!! Recursion is a function that uses itself in the same function. What a wonderful yet quite effective method!!! Who thought about it? Recursion seems mysterious and infinite to me while tracing is like a panacea in computer science that can help me perceive all the mysteries in recursion.

Afterwards

Recursion is something unbelievable and fascinating in my mind now. It also solves many problems that have lingered in my mind for a long time, exempli gratia, how to get the sum of a list that has countless nested lists. After I was enjoying in tracing all the codes, the fact struck me again... I found it extremely hard to write one by myself! To write one seems much harder than to trace one. How could that happen?? Does that mean I didn't carefully listen to my teacher? No it's not, after going to piazza, a website to ask and answer questions about the courses, I realize it is not required at that point. Yet, I still successfully created one during the laboratory at Thursday night.