cs428 12
cs428 12
cs428 12
Announcements
Midterm next Tuesday 12:30-1:45
Room MEB 253 netid a*-jke* Room DCL 1310 (this) netid jmc*-z* Rules like in previous years Conflict: email Steve by the end of the day
A good design
Satisfies requirements Easy to implement Easy to understand Easy to change Easy to check for correctness Is beautiful
CS428
12-3
Keep it Simple
Eliminate duplication Eliminate unnecessary features Hide information No surprises (follow standards)
CS428
12-5
CS428
12-6
Davis
The design should be structured to degrade gently, even when aberrant data, events, or operating conditions are encountered. The design should be assessed for quality as it is being created, not after the fact. The design should be reviewed to minimize conceptual errors.
CS428 12-7
Design: Verb
Bounce from high-level to low-level New requirements come after design is created Design is created incrementally
As requirements are known As better design ideas are invented As design flaws are discovered
CS428 12-8
Low-level Design
Many different techniques
Flow charts Decision tables Pseudo-code State machines
CS428
12-9
Decision tables
Used to specify program with complex conditions Makes it easy to see if any cases are missing Can be implemented with IF statements
CS428
12-10
Actions
27.5 years 31.5 years 39 years 50 years 22 years x x
x
x x
CS428 12-12
Pseudo-code
Also known as Program Design Language Advantages:
Expressive and compact Can use any editor (Sometimes) can compile it
Disadvantages:
Must know the language
CS428 12-13
Pseudo-code
float computerRecoveryPeriod(property) { if (isReal(property)) { if (isResidential(property)) return 27.5; if (onReservation(property)) return 22; if (isRailroad(property)) return 50; if (property.date > May 13, 1993) return 31.5; else return 39; } }
CS428 12-14
Pseudo-code
Works well with refinement Write pseudo-code
As comments With stubs
CS428
12-15
30 2 R/R 4 Y/R 25
CS428
R/G
R/Y
4 R/R 2
G/R
Implementing socket
Socket is an object Actions are methods of the socket State is stored in variable of the object Each method uses IF statement to make sure socket is in the right state When IF statements get too complicated, use State Pattern
CS428 12-20
State Pattern
From Design Patterns
ConnectingState
Socket SocketState listen() connect() newconn1() ... ConnectedState ... PassiveState
CS428
12-21
Detailed design
Lots of different techniques Most only works in a few places Pseudocode works most places, but often there is a better technique Often best to use code and skip detailed design
CS428
12-22
Good design
Good design is product of many small steps Do the right thing
Each step adds a feature Do one more thing right
Next: Midterm
Tuesday, March 9, 12:30-1:45 Two rooms
Check Wiki and newsgroup for details
Material includes all lectures and readings until today, including guest lecture
CS428 12-24