review of c++ elements
a class collects data and the methods used to access or change the data
such a collection of data(data members) and methods(methods or member functions) is called an object belonging to the given class
information hiding:by relying on its specification,a client can use a method without needing to know how the data are actually stored or how the methods are actually programmed.
Public:data members and methods available to a client are called public
Private:can be used in the implementation of the class,but are not available to a client
Convention(约定俗成)methods of a class are public ; funcitons in a class are private
Utility package(多用途工具包)util包:contains various declarations and functions.even these are not related to each other,we put them in a class
Clients:user programs with access to a particular class,can declare and manipulate(操纵) objects of that class.e.g. declare a Life object:Life configuration.
Members selection operator(成员访问运算符 包括. 和 ->)
Apply methods to work with configuration:configuration.print()
Preconditons state what is required before;postconditons state what has happened when the method ,function,or program has finished
Use classes to model the fundamental concepts of the program
Each function should do only one task,but do it well
Each class of function should hide something
Input parameters—passed by value or by reference(const)
Output parameters—passed by reference(suggest)
Local variables-defined in the funcction and exist only while the function is being executed
Global variables—dangerous,cause side effect
Stubs(占位程序)
To compile each function and class separately
To compile the main program correctly,there must be something in the place of each function that is used,so put in short,dummy functions.
e.g.
void instruction(){}
bool user_says_yes() {return false;}
drivers:a short auxiliary whose purpose is to provide the necessory input for the fuction,and evaluate the result:so that each function can be isolated and studied by itself
black-box method:effictive(most subtle error occur in the interface between functions
glass-box method:trace all the paths through the program,for a single small method
ticking-box method:just hope(?!
Program maintenance程序维护
First step is to begin the continuing process of review,analysis,and evaluation.
。Problem specification
。program correctness
。user interface
。modularity and struct
。documentation
。efficiency
Program revision and redevelopment
Review the logic
Optimize a program after it works,(it is correct
能跑就不优化
Keep functions short
Be sure your algorithm is correct
Verify the intricate parts of algorithm