Tuesday, February 17, 2015

Week 6: Object-oriented Programming Concepts

Sorry for posting late.

For all materials what we have learned from past six weeks, our main task and purpose is to learn how to design a class by ourselves. There are several concepts that oriented us to do programming.

Abstract data types(ADTs):
An abstract data type specifies clearly several methods and the docstrings and semantics of these operations which tell us what these methods work for, however, these operations do not particularly express the implementation of the operations, which make ADT abstract.
As a typical abstract data type, stack is a last in,first out data structure, which means you removed the first item you inserted, then add it to the last position. Stack works with __init__, push, pop and is_empty these four interface operations. After implementating these methods, stack can help other classes run.

Class:
We define a class to help us solve problems easily with a set of methonds.
Class objects contain attributes and instantiations.The attributes in class refer to specific types of items in class. For example, self.point refers to the coordinate of a point which could be expressed as a tuple of two integers. The class instantiations are to return new instance which is our desired result through using some functions and methods.
Futhermore, we also learned class inheritence(subclass), which is to design a parent class that contains all general methods and instances and one son class or several subclasses to do specific works. For example, what I've done in my first assignment with my group members is to design a general game class which contains general game state, such as players' turn, state of moving and so on. Then we implemented subclasses for a substract square game. In next assignment, we will design subclasses for a new game based on our past parent main class, general game class. And we also need to raise exceptions to let users of class to know that if they want to run specific subclass, they need to inplemented relevant missing materials.

Recursion:
"When a function calls itself, we say that it is recursive." Recursion is not the only way to solve problems, however, recursion is necessary for computer scientists because of its conciseness.
Recursion data structures: usually are composed of simple instances of themselves, for instance, list of numbers, and nested number lists.

References:
[1] Posted slides from course website.
[2] https://docs.python.org/3/tutorial/classes.html

No comments:

Post a Comment