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
Tuesday, February 17, 2015
Sunday, February 8, 2015
Week 5: First Midterm
We finished our first midterm in week 5. During the test, this series of learning and practical application in past 5 weeks, I found that a lot of their own inadequencies because I didn't respond to test questions immediately and what we tested in our midterm were just about our lab materials. I feel disappointed with myself.
In our fourth lab, we have started a new materials we have learnt from lecture in this week what is about test and unittest which we partly learnt in CSC108 lectures. Test is one of the most significant steps in programming, that's to say, a completed program is required to pass in various problems regions and all special cases. Therefore, a intergral set of problem cases is determined by a clear classification for different types of special cases.
Sunday, February 1, 2015
Week 4: Review and Question
In these
four weeks, I have expanded what I have
learned about how to write class from CSC108. That's to say, I should know how
to apply what I have know about writing class to solve real problems in our
live. As what our assignment 1 required us to do, what we should do is to design several
classes to run a game or several different games in the future. These classes
contained both main class and subclass. To design these classes well, it's
important to know relationship between main class and sub class and also have
clear comprehension of what subclass inherits from main class and what should
it do with its own work.
However,
when I worked with my partners, at the beginning of our assignment, we both
misunderstood the main purpose of our assignment. Because what the instruction
told us was to design five specific classes to finish whole construction of
subtract-square game, whereas we thought we can finish this game by exactly one
class and ignored the importance of subclass and continuity of our assignment.
Fortunately, I've asked Diane and she gave us a comprehensive understanding of
this assignment. What I and my partners should pay high attention to is to read
our instruction of assignment carefully so that we could avoid unwanted and
stupid mistakes.
Since the
first midterm is coming, I should make careful review of what I have learnt
from the lectures and mistakes of this assignment. And I also have a question
about subclass. For the property of subclass itself, should it write as name of
subclass itself or inherit from main class?(e.g., In __init__ of subclass, can
it be written like '(Employee) -> Nonetype' or '(HourlyEmplyee) ->
Nonetype' ?)
Subscribe to:
Posts (Atom)