20
Binghamton University CS-211 Fall 2015 Software Design 1

Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Embed Size (px)

Citation preview

Page 1: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Software Design

1

Page 2: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Typical Life Cycle of an Application

Requirements

Design

ImplementSupport

Evaluate

2

Page 3: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Design starts from Specifications

• No good formal method of capturing specifications

• Figuring out HOW to meet the specifications

• Without violating the constraints from the specifications

3

Page 4: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

The Software Design Problem

• Small projects can be managed in your head• You can design and remember all the details of the design without writing

anything down

• Larger projects are too big to design in your head• Need a way to split up a big problem into smaller pieces

4

Page 5: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Design Concepts

• Abstraction – reducing information content, retaining only information which is most relevant

• Information hiding – Preventing implementation details from interacting with the abstract view

• Algorithm – Language independent method for solving a problem

• Modularity – Dividing a problem into smaller sub-problems

• Architecture – How modules interact with each other

• Stepwise Refinement – Modularizing the Modules

• Design Patterns – Previous solutions to similar problems

5

Page 6: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Example Design Process - Specifications

• Create a filter that replaces every occurrence of a “from” string with an occurrence of a “to” string

• “from” string represented as a parameter – no symbols or spaces

• “to” string optional parameter – no symbols or spaces

• Read input data from stdin

• Write output data to stdout

• Each input/output line less than 1024 bytes long

6

Page 7: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Design Step 1 - Abstraction

read parameters

while(read next line from stdin) {

apply filter to single line

write single line to stdout

}

return success

7

Page 8: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Design Step 2 – Design Pattern

How do I filter a single line (string)?

Alternatives:

• Treat the string as an array of characters

• Use standard library string functions

8

Page 9: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Design Step 3 – Stepwise Refinement

• Assuming array of characters…

• How do I check to see if the “from” string occurs in the “input” string?

9

input

M a r y h a d a l I t t l e l a m b \n \0

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

from

M a r y \0

0 1 2 3 4

Page 10: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Design Step 4 - Algorithm

Q: Does “from” appear starting at position “i” in input?

assume match = true

for(k - position in from) {

if (input[i+k] != from[k])

match=false , break

}

if match is true, “from” appears at position i

10

Page 11: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Design Step 5 - Algorithm

for (i – position in “input”) {

if (match(from,input[i]) {

write “to” string to output

move “i” past “from” string in input

} else {

copy input[i] to output

}

}

11

Page 12: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Algorithm Using string functions

iptr – pointer to input string left (starts at input[0])

fptr – pointer to next match with “from” starting at iptr

while(fptr=strstr(from,iptr)) {

write from iptr to fptr to output

write “to” string to output

increment iptr to fptr + “from”

}

write from iptr to end of input string to output

12

Page 13: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Documenting the Design

• Pseudo-Code

• FlowCharts

13

Page 14: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Designing the Data Flow

14

Page 15: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Data Structures

• We’ve seen several so far• Vectors, Matrices, Linked Lists, Trees

• Data Structure choice is part of the design

• Need to know what data structures are good for

• For instance, do I want to keep my input string as linked list?

15

Page 16: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Object Orientation

• Design Pattern – way of thinking about the world

• More next lecture.

16

Page 17: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Design Considerations

• Correctness

• Maintainability, Modularity, Usability, Performance

• Fault-Tolerance, Reliability, Robustness, Security

• Compatibility, Extensibility, Reusability, Scalability, Portability

17

Page 18: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Design Principles

• Consider Alternatives

• Cross-Link with the Specifications

• Make use of existing solutions

• Connect Design to the Real World

• Uniformity

• Accomodate change

18

Page 19: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Design Evolution

• Design Evolves over time

• Specifications Evolve

• Discovery during Design, Implementation, and Testing

• The later a design changes, the more it costs to fix!

• Extra Effort in design will save you time and effort!

19

Page 20: Software Design - Binghamtontbarten1/CS211_Fall_2015/lectures/L31...M a r y \0 0 1 2 3 4. Binghamton University CS-211 Fall 2015 Design Step 4 - Algorithm Q: ... Documenting the Design

Binghamton

University

CS-211

Fall 2015

Binghamton

University

CS-211

Fall 2015

Resources

• Programming in C, No references.

• Wikipedia Software Design https://en.wikipedia.org/wiki/Software_design

• Wikipedia Flowchart https://en.wikipedia.org/wiki/Flowchart

• Software Design Tutorials• http://www.tutorialspoint.com/software_engineering/software_design_b

asics.htm

• http://www.yacoset.com/Home/how-to-design-a-computer-program

20