320 likes | 329 Views
Software Design. i206 Fall 2010 John Chuang. Some slides adapted from Glenn Brookshear, Brian Hayes, Marti Hearst, or James Landay. Confidentiality Integrity Authentication …. Software Design. Distributed Systems. C/S, P2P Caching. Security. Cryptography. Network. Standards
E N D
Software Design i206 Fall 2010 John Chuang Some slides adapted from Glenn Brookshear, Brian Hayes, Marti Hearst, or James Landay
Confidentiality Integrity Authentication … SoftwareDesign Distributed Systems C/S, P2P Caching Security Cryptography Network Standards & Protocols sockets Inter-process Communication Methodologies/ Tools Principles TCP/IP, RSA, … UML, CRC OperatingSystem Formal models Application Design Process I/O Finite automata regex Context switch Process vs. Thread Locks and deadlocks Algorithms Program Analysis Memory hierarchy ALUs, Registers, Program Counter, Instruction Register Memory Big-O Compiler/ Interpreter Assembly Instructions Data Structures Register, Cache Main Memory, Secondary Storage Searching, sorting, Encryption, etc. Machine Instructions CPU Op-code, operands Instruction set arch Data storage Stacks, queues, maps, trees, graphs, … Circuits Lossless v. lossy Info entropy & Huffman code Decimal, Hexadecimal, Binary Adders, decoders, Memory latches, ALUs, etc. Gates Data compression Number Systems Data AND, OR, NOT, XOR, NAND, NOR, etc. Boolean Logic Numbers, text, audio, video, image, … Truth table Venn Diagram DeMorgan’s Law Data Representation Binary Numbers Bits & Bytes John Chuang
Outline (Next 5 Weeks) • Algorithm and Program • Programming Languages and Paradigms • Object-Oriented Design • Analysis of Algorithms • Data Structures • Regular Expressions John Chuang
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
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
Folding a Bird from a Square Piece of Paper Origami Primitives John Chuang Source: Brookshear
Sequential Search Algorithm in Pseudocode Source: Brookshear • Pseudocode primitives in bold John Chuang
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
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://webopedia.internet.com/TERM/P/programming_language.html Source: Brookshear, Figure 6.2 John Chuang
http://xkcd.com/303/ John Chuang
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
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
OOP Example John Chuang Source: http://www.stanford.edu/~gpathy/umlshort/
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
knows information performs services an object maintains connections (to other objects) makes decisions (to do the right things) 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) John Chuang Source: Wirfs-Brock and McKean, Object Design: Roles, Responsibilities, and Collaborations.
knows information performs services a collaborator maintains connections (to other objects) makes decisions (to do the right things) Collaboration needs help • Collaboration: an interaction of objects or roles (or both) • Contract: an agreement outlining the terms of a collaboration message asking for help an object John Chuang Source: Wirfs-Brock and McKean, Object Design: Roles, Responsibilities, and Collaborations.
1. Design using 3 chips (classes) 2. Design using 3 chips (classes) 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) John Chuang
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
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
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 • … John Chuang http://www.smartdraw.com/resources/centers/uml/uml.htm
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
Class Diagram • Captures the logical structure of the system, including objects and their relationships with one another Source: Brookshear, Figure 7.4 John Chuang
Class Diagram Example John Chuang Source: http://www.stanford.edu/~gpathy/umlshort/
+: public - : private Representing Classes John Chuang Source: Learning UML 2.0
Representing Classes John Chuang Source: Learning UML 2.0
Relationships between Classes Source: Learning UML 2.0 John Chuang
Relationships between Classes “HAS-A” Source: Learning UML 2.0 John Chuang
Relationships between Classes Source: Learning UML 2.0 “IS-A” Note: Inheritance is also known as generalization John Chuang
Class Diagram Example John Chuang Source: http://www.stanford.edu/~gpathy/umlshort/
Collaboration Diagram • Shows interactions between classes for one or more use cases John Chuang Source: Brookshear, Figure 7.6
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
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! Traditional Software Life Cycle John Chuang http://www.math.bas.bg/~nkirov/2004/Horstman/ch13/images/spiral.png Source: Brookshear, Figure 7.2