University of Toronto Department of Computer Science CSC444 Lec05- 1 Lecture 5: Decomposition and Abstraction Decomposition When to decompose Identifying.

Slides:



Advertisements
Similar presentations
Chapter 14 Recursion Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas,, E. Reingold.
Advertisements

COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
PVK-HT051 Contents Introduction Requirements Engineering Project Management Software Design Detailed Design and Coding Quality Assurance Software Maintenance.
Software Engineering and Design Principles Chapter 1.
1 CMSC 132: Object-Oriented Programming II Software Development II Department of Computer Science University of Maryland, College Park.
Fall 2007CS 225 Introduction to Software Design Chapter 1.
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
Department of Computer Science University of Maryland, College Park
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 1 Program Design
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Lecture 8: Structured Design and Object Oriented Design CSE 111 7/12/20151Copyright William. E. Howden.
Spring 2009CS 225 Introduction to Software Design Chapter 1.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Introduction SWE 619. Why Is Building Good Software Hard? Large software systems enormously complex  Millions of “moving parts” People expect software.
University of Toronto Department of Computer Science CSC444 Lec04- 1 Lecture 4: Software Lifecycles The Software Process Waterfall model Rapid Prototyping.
Cs205: engineering software university of virginia fall 2006 Semantics and Specifying Procedures David Evans
University of Toronto Department of Computer Science © 2001, Steve Easterbrook CSC444 Lec22 1 Lecture 22: Software Measurement Basics of software measurement.
Lecture 18: Specifications
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
Session 05: C# Patterns Algorithm Patterns: Sweep Search FEN AK IT: Softwarekonstruktion.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
CSCI-383 Object-Oriented Programming & Design Lecture 4.
SOFTWARE ENGINEERING BIT-8 APRIL, 16,2008 Introduction to UML.
Design-Making Projects Work (Chapter7) n Large Projects u Design often distinct from analysis or coding u Project takes weeks, months or years to create.
University of Toronto Department of Computer Science © 2001, Steve Easterbrook CSC444 Lec13 1 Lecture 13: Representing software designs Viewpoints Structural.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Program Design CMSC 201. Motivation We’ve talked a lot about certain ‘good habits’ we’d like you guys to get in while writing code. There are two main.
University of Toronto Department of Computer Science CSC444 Lec08 1 Lecture 8: Testing Verification and Validation testing vs. static analysis Testing.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Introduction to Software Design Chapter 1. Chapter Objectives  To become familiar with the software challenge and the software life cycle  To understand.
1 C++ Plus Data Structures Nell Dale Chapter 1 Software Engineering Principles Modified from the Slides made by Sylvia Sorkin, Community College of Baltimore.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
Programming Life Cycle Problem analysisunderstand the problem Requirements definition specify what program will do High- and low-level designhow it meets.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
1 CSE1301 Computer Programming Lecture 24: Software Engineering.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Introduction to Computer Programming CS 126 Lecture 1 Zeke Maier.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
CSI 1340 Introduction to Computer Science II Chapter 1 Software Engineering Principles.
1 Data Structures CSCI 132, Spring 2014 Lecture 1 Big Ideas in Data Structures Course website:
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
Computer Science 112 Fundamentals of Programming II.
University of Toronto Department of Computer Science CSC444 Lec06 1 Lecture 6: Procedural Abstractions Defining procedural abstractions the parts of a.
Chapter 2 Principles of Programming and Software Engineering.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 requirements 1 what is a requirement? “a property [or behavior] that must be exhibited.
Chapter 3 Chapter Summary  Algorithms o Example Algorithms searching for an element in a list sorting a list so its elements are in some prescribed.
Principles of Programming & Software Engineering
Introduction to Algorithms
C++ Plus Data Structures
Objective of This Course
Introduction to Algorithms
Unit 1: Principles of Computer Science
Chapter 2. Problem Solving and Software Engineering
Top-Down Design & JSP Skill Area Part D
Presentation transcript:

University of Toronto Department of Computer Science CSC444 Lec05- 1 Lecture 5: Decomposition and Abstraction Decomposition When to decompose Identifying components Modelling components Abstraction Abstraction by parameterization Abstraction by specification Pre-conditions and Post-conditions © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec05- 2 Decomposition Tackle large problems with “divide and conquer” Decompose the problem so that: Each subproblem is at (roughly) the same level of detail Each subproblem can be solved independently The solutions to the subproblems can be combined to solve the original problem Advantages Different people can work on different subproblems Parallelization may be possible Maintenance is easier Disadvantages Solutions to the subproblems might not combine to solve the original problem Poorly understood problems are hard to decompose © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec05- 3 Decomposition can work well: E.g. designing a restaurant menu Decomposition doesn’t always work E.g. writing a play: Decomposition isn’t always possible for very complex problems (e.g. Managing the economy) for impossible problems (e.g. Turning water into wine) for atomic problems (e.g. Adding 1 and 1) Decomposition Examples Choose a set of character parts write character 1’s part write character 2’s part write character 3’s part …etc… merge Choose style and theme Design appetizers menu Design entrees menu Design desserts menu Design drinks menu Assemble and edit © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec05- 4 How to decompose Step 1: Identify components a good decomposition minimizes dependencies between components coupling - a measure of inter-component connectivity cohesion - a measure of how well the contents of a component go together information hiding having modules keep their data private provide limited access procedures this reduces coupling Private data Private data.x=? “42!” module a module b © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec05- 5 How to decompose (cont.) Step 2: Model the components At the design level At the coding level dataflow diagrams structure charts object diagrams procedure specifications procedure declarations float sqrt(int); float sqrt(int x){ /* requires: x is a positive integer effects: returns an approximation of the square root of x to within ±10 -4 */ © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec05- 6 Abstraction Abstraction is the main tool used in reasoning about software Why? It allows you to: ignore inconvenient detail treat different entities as though they are the same simplify many types of analysis Example abstractions graph directed graph undirected graph treeDAG... A file A sequence of bits on a disk set membership A program that takes an integer and a list returns the index of the first occurrence of the element or null if the element does not occur in the list... © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec05- 7 example Can I replace A with B? if we could abstract away all the detail… found = false; i = lowbound(a); while (i < highbound(a)+1){ if (a[i] == e) { z = i; found = TRUE; } i = i + 1; } found = false; i = lowbound(a); while (i < highbound(a)+1){ if (a[i] == e) { z = i; found = TRUE; } i = i + 1; } found = false; i = highbound(a); while (i > lowbound(a)-1){ if (a[i] == e) { z = i; found = TRUE; } i = i - 1; } found = false; i = highbound(a); while (i > lowbound(a)-1){ if (a[i] == e) { z = i; found = TRUE; } i = i - 1; } AB © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec05- 8 Using Abstraction Abstraction can help with Decomposition e.g. To manage the economy, try focussing on some abstracted features such as inflation, growth, GDP, etc. Abstraction allows us to ignore inconvenient details In programming: Abstraction is the process of naming compound objects and dealing with them as single entities (i.e. ignoring their details) Abstraction doesn’t solve problems… …but it allows us to simplify them © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec05- 9 Abstraction by Parameterization The program fragment: x * x - y * y computes the difference of the squares of two specific variables, x and y. The abstraction: int squares (int x, int y) { return(x * x - y * y); } describes a set of computations which act on any two (integer) variables to compute the difference of their squares Note: locally the variables are called x and y for convenience The specific computation: result = squares(big, small); uses the abstraction ‘squares’ on two specific variables (‘big’ and ‘small’) © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec Abstraction by parameterization… …allows us to express infinitely many computations …but does not tell us about the intention of those computations We need to capture the intention e.g. consider what is true before and after a computation we can abstract away from a computation (or a plan, program, function, etc) by talking about what it achieves Abstraction by Specification before unsorted array after sorted array function for sorting arrays specification this function can be used whenever we have an array. After it is applied, the array will be sorted into ascending order © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec Pre-conditions and Post-conditions The two forms of abstraction are complementary parameterization allows us to perform a computation on any arbitrary variables (values) specification allows us to ignore how it is done Unfortunately… only abstraction by parameterization is built into our programming languages as function (procedure) definitions We can overcome this using comments: int strlen (char s[]) { /* precondition: s must contain a character array, delimited by the null character; postcondition: returns the length of s as an integer; */ int length = 0; while (s[length]) length++; return(length); } int strlen (char s[]) { /* precondition: s must contain a character array, delimited by the null character; postcondition: returns the length of s as an integer; */ int length = 0; while (s[length]) length++; return(length); } © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec Summary Decomposition allows us to simplify difficult design tasks A good decomposition minimizes coupling between components maximizes cohesion within components permits information hiding Methods provide… … techniques for decomposing problems … notations for describing the components Abstraction allows us to ignore detail by parameterization: allows us to describe and name sets of computations by specification: allows us to ignore how the computation is done © 2001, Steve Easterbrook

University of Toronto Department of Computer Science CSC444 Lec References van Vliet, H. “Software Engineering: Principles and Practice (2nd Edition)” Wiley,  Chapter 11 provides an introduction to the concepts in this lecture, especially section However, van Vliet does not go into much detail about documenting procedural and data abstractions in the style I use in this and the next two lectures. For this you’ll need: Liskov, B. and Guttag, J., “Program Development in Java: Abstraction, Specification and Object-Oriented Design”, 2000, Addison-Wesley.  See especially chapters 1 and 3. I draw on Liskov’s ideas extensively for advice on program design in this course. The commenting style I use (“requires”, “effects”, etc) is Liskov’s. If you plan to do any extensive programming in Java, you should buy this book. If you don’t buy it, borrow it and read the first few chapters. © 2001, Steve Easterbrook