【文章內(nèi)容簡介】
ided Interface Subponent Required Interface Provided Interface Subponent Required Interface Provided Interface Subponent Required Interface 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Stubs Provided Interface Main ponent Required Interface Provided Interface Stub Required Interface Provided Interface Stub Required Interface Provided Interface Stub Required Interface 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Stubs Provided Interface Main ponent Required Interface Provided Interface Stub Required Interface Provided Interface Stub Required Interface Provided Interface Subponent Required Interface Provided Interface Stub Required Interface Provided Interface Stub Required Interface 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Stubs Provided Interface Main ponent Required Interface Provided Interface Subponent Required Interface Provided Interface Stub Required Interface Provided Interface Subponent Required Interface Provided Interface Stub Required Interface Provided Interface Stub Required Interface 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 ICS 52 Life Cycle Requirements phase Verify Design phase Verify Implementation phase Test Testing phase Verify 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Design/Implementation Interaction Design (previous lectures) Implementation (this lecture) 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 From Design to Implementation 1. Choose a suitable implementation language 2. Establish coding conventions 3. Divide work effort 4. Implement ? Code ? Unit tests ? Code reviews ? Inspections 5. Perform integration tests 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Choose a Suitable Language ? 4th Generation language ? Databases ? Visual Basic ? Forms ? “Real” programming language ? Java + Class Libraries ? C++/C + STL (Standard Template Library) ? Cobol ? Fortran ? Assembly language ? Machine specific 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Choose a Suitable Language ? Maintain the design “picture” ? Mapping of design elements onto implementation ? Module inside versus outside ? Does the language enforce a boundary? ? Interfaces! ? Explicit representation of uses relationship ? Just function calls? ? Error handling ? Return values ? Exceptions 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Establish Coding Conventions ? define _POSIX_SOURCE /* you are not supposed to understand this */ define O(OOO,OO0,O00,O0O,OO,O0)\0O0O%:%:OO\0O0%:%:OOO\0OO0%:%:O00 include static volatile sig_atomic_t One。 include include define Zero(NULL)NULL define ONE(One) Zero(One) in??/ t line 10 01\015 main (register zero, char **ONE) %: } 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Java Too! ? import .*。import .*。public class C extends Frame{Date D=new Date()。void T(Date d){D=d。repaint()。}double P=,A=P/2,a,c,U=.05。int W,H,m,R。double E(int a,int u){return(3*P/2+2*P*a/u)%(2*P)。}void N(Graphics g,double q,double s){(new int[]{H(s,q),H(U,q+A),H(U,q+3*A)},new int[]{J(s,q),J(U,q+A),J(U,q+3*A)},3)。}public void paint(Graphics g){Color C=。(C)。(0,0,W=size().width,H=size().height)。W=52。H=52。R=(W/2,H/2)。(W/2+25,H/2+36)。(C.darker())。for(m=0。m12。++m){a=E(m,12)。(H(.8),J(.8),H(.9),J(.9))。}m=()。N(g,E(()*60+m,720),.5)。N(g,E(m,60),.8)。N(g,E((),60),.9)。}int H(double y){return(int)(R*y*(a))。}int H(double y,double q){a=q。return H(y)。}int J(double y){return(int)(R*y*(a))。}int J(double y,double q){a=q。return J(y)。}public static void main(String[]_)throws Exception{C c=new C()。(200,200)。()。for(。){(new Date())。(200)。}}} 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Establish Coding Conventions ? Naming ? Avoid confusing characters ? 1, l, L, o, O, 0, S, 5, G, 6 ? Avoid misleading names ? Avoid names with similar meaning ? Use capitalization wisely ? Code layout ? White space / blank lines ? Grouping ? Alignment ? Indentation ? Parentheses 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Divide Work Effort ? Assign different modules to different developers ? Assignments can be incremental ? Assignments change ? Illness ? New employees ? Employees who quit ? Schedule adjustments ? Star programmers ? Interfaces are tremendously important ? “Contracts” among modules 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Coding ? FIRST MAKE IT WORK CLEANLY ? FIRST MAKE IT WORK CLEANLY ? FIRST MAKE IT WORK CLEANLY ? FIRST MAKE IT WORK CLEANLY ? FIRST MAKE IT WORK CLEANLY ? FIRST MAKE IT WORK CLEANLY ? FIRST MAKE IT WORK CLEANLY ? FIRST MAKE IT WORK CLEANLY ? FIRST MAKE IT WORK CLEANLY 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Code Optimizations ? Only make optimizations to a cleanly working module if absolutely necessary ? Performance ? Memory usage ? Isolate these optimizations ? Document these optimizations Empirical evidence has proven that these optimizations are rarely needed and that if they are needed, they are only needed in a few critical places 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Defensive Programming ? Make your code robust and reliable ? Use assertions ? Use tracing ? Handle, do not ignore, exceptions ? Contain the damage caused ? Garbage in does not mean garbage out ? Anticipate changes ? Check return values ? Plan to be able to remove debugging aids in the final, deliverable version Do not sacrifice any of these when facing a deadline 169。 2021, Univ ersity of C alifornia, Irv ine Lecture 51 Comments ? Self documenting code does not exist! ? Meaningful variable names, crisp code