Compare with Structure programming,Object_oriented programming(OOP) is mainly focus on building new object and using object features.
For past two weeks, we were learning how to design new class to solve given problem.Like,build "Stack" object to pop or check if a stack is empty.If not consider the OOP,we can do the same operation by write functions,but these function can only be used in single document.By build class(object),we can apply operations about "Stack" into any functions if we want,that is initial advance of OOP.
Before learning object_oriented programming,I used to prefer design functions step by step.It can run correctly.However,when I met a similar but not all-the-same problem,I had to rewrite my function even it only needed slightly adjustments.Now,by building classes,a KIND of problem can be sorted into same condition.This method of programming improves the efficiency cause it avoid duplicate.
Design a new class is like infusing certain characteristics into the processing object.And analysing the description of our assignment is the procedure to extract the function aim,like what purpose does this function design for?From this prospective,the aim and consequence of function should correspond to the characteristics of object.Unfortunately, I find it hard to link the problem that I try to solve to certain objects that might help.In other words, I cannot make clear the steps I need.To get through this difficulty,I change the direction of thinking. I always think from prerequisites to results.Now I think in reverse inference,which means I start from result,deduce back until it fits the given conditions.Also,I draw flow diagrams.It clarifies the logic between each step and list out all possibilities I need to consider.
Monday, 20 January 2014
Sunday, 19 January 2014
Where should I place contracts EXACTLY?
From CSC108 class we've learned,by following function design recipe, the contract should be place like below:
def whatever(a,b):
'''(int, int) -> int
'''
It runs smoothly and shows no error in WingIDE.
But for CSC148 class, the example is like:
always shows syntaxerror.
However, the contract error does not affect running body of the function.But it's still indicates error in WingIDE.
Why.
def whatever(a,b):
'''(int, int) -> int
'''
It runs smoothly and shows no error in WingIDE.
But for CSC148 class, the example is like:
always shows syntaxerror.
However, the contract error does not affect running body of the function.But it's still indicates error in WingIDE.
Why.
Subscribe to:
Posts (Atom)