Software Design i206 Fall 2010 John Chuang Some slides adapted from Glenn Brookshear, Brian Hayes, Marti Hearst, or James Landay.

Post on 21-Dec-2015

221 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

Transcript

Software Design

i206 Fall 2010

John Chuang

Some slides adapted from Glenn Brookshear, Brian Hayes, Marti Hearst, or James Landay

John Chuang 2

SoftwareDesign

Bits & BytesBinary Numbers

Number Systems

Gates

Boolean Logic

Circuits

CPU Machine Instructions

Assembly Instructions

Program Algorithms

Application

Memory

Data compression

Compiler/Interpreter

OperatingSystem

Data Structures

Analysis

I/O

Memory hierarchy

Design

Methodologies/Tools

Process

Truth tableVenn DiagramDeMorgan’s Law

Numbers, text,audio, video, image, …

Decimal, Hexadecimal, Binary

AND, OR, NOT, XOR, NAND, NOR,etc.

Register, CacheMain Memory,Secondary Storage

Context switchProcess vs. ThreadLocks and deadlocks

Op-code, operandsInstruction set arch

Lossless v. lossyInfo entropy & Huffman code Adders, decoders,

Memory latches, ALUs, etc.

DataRepresentation

Data

Data storage

Principles

ALUs, Registers,Program Counter, Instruction Register

Network

Distributed Systems Security

Cryptography

Standards & Protocols

Inter-processCommunication

Searching, sorting,Encryption, etc.

Stacks, queues,maps, trees, graphs, …

Big-O

UML, CRC

TCP/IP, RSA, …

ConfidentialityIntegrityAuthentication…

C/S, P2PCaching

sockets

Formal models

Finite automataregex

John Chuang 3

Outline (Next 5 Weeks)

Algorithm and Program Programming Languages and Paradigms Object-Oriented Design Analysis of Algorithms Data Structures Regular Expressions

John Chuang 4

Algorithm and Program

An algorithm is an ordered set of unambiguous, executable steps that defines a terminating process.- named after 9th century Persian mathematician Abu Ja'far Mohammed ibn Musa al-Khowarizmi

A computer program is a representation of an algorithm which prescribes the actions that are to be carried out by a computer. - A computer program consists of a set of instructions that the computer understands.

John Chuang 5

Algorithms: Levels of Abstraction

Problem: motivation for algorithm

Algorithm: procedure to solve the problem- Often one of many possibilities

Representation: description of algorithm sufficient to communicate it to the desired audience- Always one of many possibilities

John Chuang 6

Folding a Bird from a Square Piece of Paper

Source: Brookshear

Origami Primitives

John Chuang 7

Sequential Search Algorithm in Pseudocode

Source: Brookshear

Pseudocode primitives in bold

John Chuang 8

Algorithm and Program

An algorithm is an ordered set of unambiguous, executable steps that defines a terminating process.

A computer program is a representation of an algorithm which prescribes the actions that are to be carried out by a computer. - A computer program consists of a set of instructions that the computer understands.

John Chuang 9

Programming Languages

Machine language (1st generation) Assembly language (2nd generation)

- Simply a set of abbreviations for the machine code instructions- An assembler is used to translate the program into machine instructions

High-level language- A compiler or an interpreter is used to translate the program into

machine instructions

http

://w

ebop

edia

.inte

rnet

.com

/TE

RM

/P/p

rogr

amm

ing_

lang

uage

.htm

lSo

urce

: Bro

oksh

ear,

Fig

ure

6.2

John Chuang 10

http://xkcd.com/303/

John Chuang 11

Programming Paradigms

Imperative programming- describes computation in terms of statements that change a program state

- Consistent with the sequential execution of instructions in hardware

- E.g., procedural programming, object-oriented programming

Declarative programming- Describe desired results, without explicit description of steps

- E.g., regular expressions, functional programming, logical programming

John Chuang 12

Imperative Programming

Procedural programming- Specifies a sequence of algorithmic steps- Use of procedures (aka routines, subroutines, functions, or methods) to improve modularity, reuse

Object-oriented programming- Specifies a collection of objects, each with its own data and methods, and the collaborations between the objects

- OOP promotes modularity and reuse via abstraction, encapsulation, inheritance

- Helps keep large software projects, and projects with changing requirements, manageable

John Chuang 13

OOP Example

Source: http://www.stanford.edu/~gpathy/umlshort/

John Chuang 14

Object-Oriented Design

Object-oriented design based upon principles of abstraction, encapsulation, and modularity

Object-oriented design through the clarification of object roles, responsibilities, and collaborations

John Chuang 15

Role and Responsibility

Application: a set of interacting objects Object: an implementation of one or more roles Role: a set of related responsibilities Responsibility: an obligation to perform a task (action) or to know information (data)

Source: Wirfs-Brock and McKean, Object Design: Roles, Responsibilities, and Collaborations.

an object

knows information performs services

maintains connections(to other objects)

makes decisions(to do the right things)

John Chuang 16

Collaboration

Collaboration: an interaction of objects or roles (or both)

Contract: an agreement outlining the terms of a collaboration

Source: Wirfs-Brock and McKean, Object Design: Roles, Responsibilities, and Collaborations.

a collaborator

knows information performs services

maintains connections(to other objects)

makes decisions(to do the right things)

an object

needs help

message asking for help

John Chuang 17

Cohesion and Coupling Q: how to come up with the right set of objects for a system?- Maximize cohesion (relationship within object)- Minimize coupling (relationship between objects)

ALU

SHIFTER

RegistersALU

Shifter

Chip 1 Chip 2

Chip 3

1. Design using 3 chips (classes)Chip 1 Chip 2

Chip 3

AND gates OR gates

NOT gates

2. Design using 3 chips (classes)

John Chuang 18

Cohesion and Coupling

Design 2 has too much coupling and not enough cohesion. As a result, it is:- difficult to understand- difficult to locate faults- difficult to reuse, extend, or enhance

Design 1 has better abstraction, encapsulation, and modularity

John Chuang 19

OO Analysis & Design Process

Gather requirements Develop use cases

- Each use case describes what the system does to accomplish a particular customer goal

Analysis and Design- Iterative process of identifying roles, responsibilities, and collaborations

- Textual analysis- Noun analysis to identify candidate classes- Verb analysis to identify candidate methods

- Identification and use of design patterns- Design pattern: a general reusable solution to a commonly occurring problem

John Chuang 20

Unified Modeling Language (UML) UML is a language for specifying, visualizing, constructing, and documenting a software system

Several types of diagrams, including:- Use Case diagrams- Class diagrams- Sequence diagrams- …

http://www.smartdraw.com/resources/centers/uml/uml.htm

John Chuang 21

Use Case Diagram A use case is a sequence of

actions a system performs that yields an observable result to an external actor- A use case describes

functionality of the system from the user's point of view

- A good use case has: a single goal, an external initiator, a start condition, and an end condition

- A use case is represented by an oval in UML

An actor is someone or something outside the system that interacts with the system- An actor can be a human being

or another system or a device- An actor is represented by a

stick figure in UML.

John Chuang 22

Class Diagram

Captures the logical structure of the system, including objects and their relationships with one another

Source: Brookshear, Figure 7.4

John Chuang 23

Class Diagram Example

Source: http://www.stanford.edu/~gpathy/umlshort/

John Chuang 24

+: public - : private

Representing Classes

Source: Learning UML 2.0

John Chuang 25

Representing Classes

Source: Learning UML 2.0

John Chuang 26

Relationships between Classes

Source: Learning UML 2.0

John Chuang 27

Relationships between Classes

Source: Learning UML 2.0

“HAS-A”

John Chuang 28

Relationships between Classes

Source: Learning UML 2.0

Note: Inheritance is also known as generalization

“IS-A”

John Chuang 29

Class Diagram Example

Source: http://www.stanford.edu/~gpathy/umlshort/

John Chuang 30

Collaboration Diagram

Shows interactions between classes for one or more use cases

Source: Brookshear, Figure 7.6

John Chuang 31

Sequence Diagram

Shows interactions between classes over time for a particular use case

Place classes at the top of diagram

Draw vertical lines down from each class

Draw horizontal lines to the vertical lines to show interactions (method calls); label lines with the name of the message or method- Time goes from diagram’s top to bottom

Source: Wikipedia

John Chuang 32

Software Design Process Software design is a creative problem solving process

- Understand the problem (create use scenarios)- Find algorithmic procedure that might solve the problem

(consider different solution options)- Formulate the algorithm and represent it as a program- Evaluate the program for accuracy and its potential as a

tool for solving other problems- Iterate!

Source: Brookshear, Figure 7.2 http://www.math.bas.bg/~nkirov/2004/Horstman/ch13/images/spiral.png

Traditional Software Life Cycle

top related