Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

cs428 12

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 24

Low-level design

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

Milestone 3 meetings are March 15-19


But practice UML part BEFORE midterm

WA3 due today


CS428 12-2

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 (S)


Everything should be as simple as possible, but no simpler. (Einstein) A design is finished not when there is nothing to add, but when there is nothing to take away. (Saint-Exupery) Measuring a program by the number of lines of code in it is like measuring an airplane by how much it weighs. (Gates)
CS428 12-4

Keep it Simple
Eliminate duplication Eliminate unnecessary features Hide information No surprises (follow standards)

CS428

12-5

Davis Design Principles


Dont reinvent the wheel. Exhibit uniformity and integration. Minimize the intellectual distance between the software and the problem as it exists in the real world. Structure the design to accommodate change.

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

Tax code example


The recovery period is 27.5 years for residential real property, 31.5 years for nonresidential real property placed in service before May 13, 1993, 39 years for nonresidential real property placed in service after May 12, 1993, 50 years for railroad gradings and tunnel bores, except that nonresidential real property on an Indian reservation has a recovery period of 22 years.

Decision table for recovery period


Conditions
Real property Residential Placed before May 13, 1993 Railroad grading or bore On Indian reservation 1 T T 2 T F T F F 3 T F F F F 4 T F T F 5 T F

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

Gradually implement it all Execute and test as you go

CS428

12-15

State Machines (FSM)


Lots of theory
How to minimize number of states How to merge state machines How to tell whether two state machines are equal

Can generate code directly from state machines


But usually do not
CS428 12-16

State diagram for stop light

30 2 R/R 4 Y/R 25
CS428

R/G

R/Y

4 R/R 2

G/R

Events are time delays, in seconds.


12-17

Pseudocode for stop light


Action = Record {integer wait, east, north} Action: Actions[1 .. 6] repeat forever for I = 1 to 6 do setEast(actions[i].east) setNorth(actions[i].north) wait(actions[i].wait) end for CS428 12-18

State diagram for sockets


uninitialized listen() passive newconn1() newconn1()

connect() active disconnect() isconnecting()

qlen!=0 isconnected() CONNECTING qlen!=0 isconnected() isconnected() accept() CONNECTED


CS428 12-19

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

Do the thing right


Each step makes design a little simpler Eliminates one more unnecessary complexity
CS428 12-23

Next: Midterm
Tuesday, March 9, 12:30-1:45 Two rooms
Check Wiki and newsgroup for details

Look at previous exams and Charlies Qs


Covered somewhat different material

Material includes all lectures and readings until today, including guest lecture
CS428 12-24

You might also like