Lecture 8: Structured Design and Object Oriented Design CSE 111 7/12/20151Copyright William. E. Howden.

Slides:



Advertisements
Similar presentations
Software Engineering Key design concepts Design heuristics Design practices.
Advertisements

Lecture 6: Software Design (Part I)
Programming Languages and Paradigms
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Structured Design. 2 Design Quality – Simplicity “There are two ways of constructing a software design: One is to make it so simple that there are obviously.
Communication between modules, cohesion and coupling
1 Software Design Introduction  The chapter will address the following questions:  How do you factor a program into manageable program modules that can.
What is Software Design?  Introduction  Software design consists of two components, modular design and packaging.  Modular design is the decomposition.
Copyright Irwin/McGraw-Hill Software Design Prepared by Kevin C. Dittman for Systems Analysis & Design Methods 4ed by J. L. Whitten & L. D. Bentley.
Software Design Deriving a solution which satisfies software requirements.
Copyright W. Howden1 Lecture 7: Functional and OO Design Descriptions.
© Copyright 2011 John Wiley & Sons, Inc.
Copyright W. Howden1 Lecture 6: Design Evaluation and Intro to OO Design Patterns.
CSE 111: Object Oriented Design. Design “To program is human but to design is divine” (WEH)
Program Design and Development
Jump to first page 1 System Design (Finalizing Design Specifications) Chapter 3d.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design Copyright 2000 © John Wiley & Sons, Inc. All rights reserved. Slide 1 Key.
 2007 Pearson Education, Inc. All rights reserved C Functions.
16/27/ :53 PM6/27/ :53 PM6/27/ :53 PMLogic Control Structures Arithmetic Expressions Used to do arithmetic. Operations consist of +,
ISBN Chapter 8 Statement-Level Control Structures.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Chapter 1 Program Design
System Implementation System Implementation - Mr. Ahmad Al-Ghoul System Analysis and Design.
Dr. Ken Hoganson, © August 2014 Programming in R STAT8030 Programming in R COURSE NOTES 1: Hoganson Programming Languages.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
CS 331 Modules Chapter 6. Overview Decomposition and abstraction Program organization Abstract vs. concrete User-defined types Example discussion.
1/19 Component Design On-demand Learning Series Software Engineering of Web Application - Principles of Good Component Design Hunan University, Software.
Simple Program Design Third Edition A Step-by-Step Approach
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
University of Toronto Department of Computer Science CSC444 Lec05- 1 Lecture 5: Decomposition and Abstraction Decomposition When to decompose Identifying.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Program Design Simple Program Design Third Edition A Step-by-Step Approach 9.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Cohesion and Coupling CS 4311
Systems analysis and design, 6th edition Dennis, wixom, and roth
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
sequence of execution of high-level statements
Programming Languages and Paradigms Imperative Programming.
Procedural programming in Java Methods, parameters and return values.
Control Structures sequence of execution of high-level statements.
CCSB223/SAD/CHAPTER131 Chapter 13 Designing the System Internals.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
1 COS 260 DAY 12 Tony Gauvin. 2 Agenda Questions? 5 th Mini quiz –Chapter 5 40 min Assignment 3 Due Assignment 4 will be posted later (next week) –If.
W E E K F I V E Control Flow. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 8 Topics Introduction Selection Statements Iterative Statements.
MANAGING COMPLEXITY Lecture OO01 Introduction to Object-oriented Analysis and Design Abstract Data Types.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
SOFTWARE DESIGN & SOFTWARE ENGINEERING Software design is a process in which data, program structure, interface and their details are represented by well.
Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Further Modularization, Cohesion, and Coupling. Simple Program Design, Fourth Edition Chapter 9 2 Objectives In this chapter you will be able to: Further.
CSE3302 Programming Languages (notes continued)
7. Modular and structured design
Coupling and Cohesion Rajni Bhalla.
Coupling and Cohesion 1.
Software Design Mr. Manoj Kumar Kar.
Systems Analysis and Design
Application Development Theory
Chapter 8: Control Structures
Cohesion and Coupling Chapter 5, Pfleeger 01/01/10.
Designing and Debugging Batch and Interactive COBOL Programs
Improving the Design “Can the design be better?”
Software Design CMSC 345, Version 1/11.
Software Design Lecture : 9.
Using Decision Structures
Cohesion and Coupling.
Introduction to the Lab
Presentation transcript:

Lecture 8: Structured Design and Object Oriented Design CSE 111 7/12/20151Copyright William. E. Howden

Structured Design Software engineering for procedural programming – Detailed design Structured Programming Constructing “well structured” programs – structure refers to control-flow as in a flow chart – Architectural Design Components and relationships Components: – (collections of) procedures and methods 7/12/2015Copyright William. E. Howden2

Detailed Design Structured Programming Goal: well-structured programs Basic idea – restrict all program structures to those that can be constructed from several basic constructs, plus a well defined rule of composition for building new structures 7/12/2015Copyright William. E. Howden3

The Three Basic Structured Programming Constructs Sequencing S1; S2 Alternation if C then S1 else S2 Iteration while C do S1 Variations on the above one-sided alternation, until and for loops, switches 7/12/2015Copyright William. E. Howden4

Elements of a Construct Each element Si in the above diagrams is: – another structured programming construct – a procedure/method call – an elementary statement such as an assignment or basic operation such as a string edit Each element Ci is a Boolean expression 7/12/2015Copyright William. E. Howden5

Composition: Constructing More Complex Structures by Nesting Start with statement S: e.g. if C1 then T1 else T2 – then nest additional constructs inside S by substituting them in for T1 and T2 – We can do this repeatedly, to get, for example: if C1 then( if C2 then (S1; (S2; S3)) else S4) else (while C3 do (S5; S6)) this has been constructed from one double-nested application of sequencing, 2 nested sequencings, 1 nested alternation and 1 nested iteration 7/12/2015Copyright William. E. Howden6

Compound Construct Formatted for Readability if C1 then( if C2 then (S1; (S2; S3)) else S4) else (while C3 do (S5; S6)) if C1 then( if C2 then (S1; S2; S3)) else S4) else (while C3 do (S5; S6)) 7/12/2015Copyright William. E. Howden7

Basic “Axioms” of Structured Programming Adequacy: all computations can be programmed using the three basic constructs plus the nesting rule of program composition Well-structured: if this approach to construction is used, then it is not possible to construct “poorly structured” code – poorly structured code? “spaghetti code”, goto’s all over the place 7/12/2015Copyright William. E. Howden8

Structured and Go-to-less Programming Modern programming languages, with compound statements that match SP constructs, naturally result in well-structured code Exception: go-to’s, which allow the construction of arbitrary (possibly bad) structures. – Unavoidable use of goto’s may occur in some cases, such as in use of assembly language – But we can still construct well–structured code if we follow the SP guidelines 7/12/2015Copyright William. E. Howden9

The Psychology of Structured Programming Even programmers have limited intellectual capabilities What does the mind find easy, when trying to read and comprehend? sequencing, alternation, and iteration control flow stacks for non-linear flow – while trying to read a linear text, we can use a stack to remember where we were when we have to go down a level due to nesting. When finished, pop the mental stack to go back to where we were. 7/12/2015Copyright William. E. Howden10

Top-Down Design TD is a kind of structured programming strategy – Abstract function/procedure at top level More detailed functions at next level etc. – This “refinement process” continues until everything is concrete source code – At each level only SP constructs are used 7/12/2015Copyright William. E. Howden11

Copyright W. Howden12 DS PseudoCode and Program Refinement 1 Member Data getADate(DaterPreferences daterPrefs) { Record record; Boolean match = false; record = filemanager(“getFirst”); see if record matches daterPrefs and set match while ((record =/ null) and (match == false)) { record = filemanager(“getNext); see if record matches daterPrefs and set match } if (match = = false) return null else return record; }

DS PseudoCode and Program Refinement 2 Next level down, refine the following into less abstract prose and actual code, or all actual code – see if record matches daterPrefs and set match 7/12/2015Copyright William. E. Howden13

Structured Programming and Object Oriented Design Can be applied to class methods In a procedural program, e.g. in C, procedures may be much larger than the average method, so SP may be more critical 7/12/2015Copyright William. E. Howden14

Architectural Design Components and Relationships Component – Separately defined collection of procedures/methods/functions and/or data definitions – Varies by programming language – Early programming languages: single procedure 7/12/2015Copyright William. E. Howden15

Component Decomposition Divide the program up into separate pieces Goals – “divide and conquer” – “intellectual manageablity” – facilitate change and reuse What are the characteristics of a good decomposition? 7/12/2015Copyright William. E. Howden16

Well-Structured Component Decomposition Cohesion: the artifacts grouped together in a component should have strong intra- relationships and should be together Goal: designs with high cohesion components Coupling: the interaction and inter- relationships between different components should be minimized Goal: designs with low inter-component coupling 7/12/2015Copyright William. E. Howden17

Copyright W. Howden18 Extreme Examples of Cohesion and Coupling One component with everything in it – Bad cohesion (probably contains weakly related elements) – Good coupling (all inter-component relationships are weak by default – there are none) Every part of a program in its own component – Good cohesion (all intra-component relationships are strong by default – there are none) – Bad coupling (things that should be together in the same component are separated) Design - balancing the goal of high cohesion against the goal of low coupling

Cohesion, Coupling and Procedural Components Cohesion and coupling concepts first developed for procedural programming in languages such as Fortran, PL-1, Algol, C, and Pascal We will introduce them using procedurally oriented concepts, and later specifically consider class oriented concepts 7/12/2015Copyright William. E. Howden19

Copyright W. Howden20 General Levels of Cohesion Coincidental Logical Temporal Procedural Data Flow Communicational Functional

Copyright W. Howden21 Coincidental Cohesion Accidental decomposition, no functional rationale – e.g. Division of code into modules determined by size consideration Isolation of commonly used but not functionally related pieces of code

Copyright W. Howden22 Logical Cohesion Group things together that are the same “kind” of thing – e.g. Module containing all the error handling routines Initialization module that opens files, initializes variables, etc.

Copyright W. Howden23 Temporal Cohesion Group things together than can be done at the same time – e.g. Initialization code component Termination/clean up component

Copyright W. Howden24 Procedural Cohesion Group things together that will be part of the same computational structure – E.g. the code that will go inside a loop – make it a separate function

Copyright W. Howden25 Data Flow Cohesion Group A,B,C together if A prepares data used by B which prepares data used by C – Why is this a stronger form of cohesion? A,B, and C must be part of the same function

Copyright W. Howden26 Communicational Cohesion Group things together than use the same data – E.g. routines for accessing DB in different ways methods for the same class

Copyright W. Howden27 Functional Cohesion Everything in component works to support a common, well defined function – you know it when you see it – E.g. good component function for computing “goodness” of a match in a complex DS – E.g. bad component calculates day of week given year/month/day computes square roots of integers

Copyright W. Howden28 Coupling Measures Kinds of coupling Amount of coupling Can be high due to either kind of coupling and/or amount of coupling High coupling may be justified by high cohesion trade-off

Copyright W. Howden29 Kinds of Coupling From high to low coupling – One module directly accesses contents of another e.g. changes data or actual code (possible in assembly or object code programming) – passing different kinds of data in a procedure call pointers control data, such as a “flag” – e.g. if flag then S1 else S2 in called procedure functional computational data

Copyright W. Howden30 Amounts of Coupling Scalar versus non-scalar – From high to low Record structures and collections (arrays, vectors) Scalar variables – From high to low Many variables Few variables

Cohesion, Coupling and Object Oriented Design Cohesion – We can construct class oriented descriptions of high and low cohesion Coupling – Procedural coupling: when one method calls a method in another class – Class coupling: when one class definition uses another class definition e.g. inheritance, class and local variable type, method parameter definition, method return type 7/12/2015Copyright William. E. Howden31

Copyright W. Howden32 Cohesion and Class Design Goal: high cohesion Levels of class cohesion, from low to high – Very low: class responsible for many things in very different functional areas – Low: class responsible for many or complex things in one functional area – Moderate: class has light or moderate responsibilities for a few different areas that are related to class but not each other – High: class has moderate responsibilities in one functional area, cooperates with others to fulfill more complex responsibilities

Coupling and Class Design Goal: – low coupling, unless cohesion and design patterns indicate otherwise – design patterns may increase coupling, but improve cohesion e.g. – state pattern creates substate classes that are coupled to the state superclass and superclass is coupled to the main class – tradeoff is better cohesion, ease of alteration 7/12/2015Copyright William. E. Howden33

Assignment 7 Write the code for your application When writing the code for the methods, keep to the spirit of structured programming Discuss two examples of non-trivial methods that you used, and how they conform to structured programming (i.e. they could have been designed in a non-structured way also) 7/12/2015Copyright William. E. Howden34