Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.

Slides:



Advertisements
Similar presentations
Design Validation CSCI 5801: Software Engineering.
Advertisements

Quality of a Class Abstraction: Coupling & Cohesion Michael L. Collard, Ph.D. Department of Computer Science Kent State University.
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.
1 SOFTWARE DESIGN QUALITY COHESION and COUPLING (Part II)
Slide 7A.1 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
Lecture 9 Improving Software Design CSC301-Winter 2011 – University of Toronto – Department of Computer Science Hesam C. Esfahani
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.
UHD::CS3320::CHAP61 INTRODUCTION TO OBJECTS Chapter 6.
Module: Definition ● A logical collection of related program entities ● Not necessarily a physical concept, e.g., file, function, class, package ● Often.
1 SOFTWARE DESIGN QUALITY COHESION and COUPLING (Part I)
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.
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Software Design Fundamentals Design Principles
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Coupling and Cohesion Source:
Design (1) Design involves decisions on how to deliver the agreed functionality to the users. Design involves development of a clear, unambiguous and consistent.
Chapter 7: Database Systems Succeeding with Technology: Second Edition.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 09. Review Introduction to architectural styles Distributed architectures – Client Server Architecture – Multi-tier.
Program Design Simple Program Design Third Edition A Step-by-Step Approach 9.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
1 Software Design Reference: Software Engineering, by Ian Sommerville, Ch. 12 & 13, 5 th edition and Ch. 10, 6 th edition.
1 Software Design Overview Reference: Software Engineering, by Ian Sommerville, Ch. 12 & 13.
SE: CHAPTER 7 Writing The Program
Cohesion and Coupling CS 4311
Systems analysis and design, 6th edition Dennis, wixom, and roth
System Implementation
Coupling & Cohesion CMSC 201- Fall '11. Vocabulary Routine- A programming unit that performs a task, such as a function, procedure, method, or main class.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Generalization. Example CachPaymentCreditPaymentCheckPayment Paymentamount sale Attribute Relationship Each sub class inherit the attribute and Relationship.
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
Slide 7.1 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented Software Engineering WCB/McGraw-Hill, 2008 Stephen R.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 20 Slide 1 Critical systems development 3.
Coupling Cohesion Chandan R. Rupakheti Steve Chenoweth (Chapter 18)
Chapter 10 Software Engineering. Understand the software life cycle. Describe the development process models. Understand the concept of modularity in.
CCSB223/SAD/CHAPTER131 Chapter 13 Designing the System Internals.
CS540 Software Design Lecture 3 & 4 1 Lecture 3 & 4: Modularity, Coupling, Cohesion and Abstraction Anita S. Malik Adapted from Schach.
Structured design - 1 © Minder Chen, Produce Paycheck Retrieve Employee Record Global Data Store Offpage Calling Module Called Module System.
Designing Classes. Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained,
Jump to first page (C) 1998, Arun Lakhotia 1 Design Quality Metrics Arun Lakhotia University of Southwestern Louisiana Po Box Lafayette, LA 70504,
Object-Oriented Design. 1 Objects and concerns Objects have a concern, meaning they have a purpose Not concerned as in worried All code should have a.
Week 6: Software Design HNDIT Software Engineering Software Design Learning Outcomes  Understand the activities involved in the Design process.
Systems Development Lifecycle
Slide 1 Good Methods. Slide 2 Cohesion and Coupling l For structured design These software metrics were used extensively Proven to be effective l For.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Slide 7B.31 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods.
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 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.
7. Modular and structured design
Coupling and Cohesion Rajni Bhalla.
Coupling and Cohesion 1.
Software Design Mr. Manoj Kumar Kar.
Class and Method Design
Cohesion and Coupling Chapter 5, Pfleeger 01/01/10.
Improving the Design “Can the design be better?”
CS223: Software Engineering
Software Design CMSC 345, Version 1/11.
Programming Logic and Design Fourth Edition, Comprehensive
Software Design Lecture : 9.
Software Design Lecture : 8
Software Design Lecture : 10
Cohesion and Coupling.
DESIGN CONCEPTS AND PRINCIPLES
Presentation transcript:

Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002

2 Characteristics of Good Design Component independence – Exception identification and handling Fault prevention and fault tolerance Design for change M3 M1M2

3 Cohesion Definition: The degree to which all elements of a component are directed towards a single task and all elements directed towards that task are contained in a single component. All elements of component are directed toward and essential for performing the same task High is good

4 Range of Cohesion High Cohesion Low Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental

5 Coincidental Cohesion Definition: Elements needed to achieve some functionality are scattered throughout the system. Accidental Worst form Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental

6 Example Print next line Reverse string of characters in second argument Add 7 to 5 th argument Convert 4 th argument to float

7 Logical Cohesion Definition: Several logically related elements are in the same component and one of the elements is selected by the client component. Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental

8 Example A component reads inputs from tape, disk, and network. All the code for these functions are in the same component. Operations are related, but the functions are significantly different.

9 Example A component reads inputs from tape, disk, and network. All the code for these functions are in the same component. Operations are related, but the functions are significantly different. Improvement

10 Temporal Cohesion Definition: Difficult to change because you may have to look at numerous components when a change in a data structure is made. Increases chances of regression fault Component unlikely to be reusable. Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental

11 Example A system initialization routine: this routine contains all of the code for initializing all of the parts of the system. Lots of different activities occur, all at init time.

12 Example A system initialization routine: this routine contains all of the code for initializing all of the parts of the system. Lots of different activities occur, all at init time. Improvement

13 Procedural Cohesion Definition: Actions are still weakly connected and unlikely to be reusable Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental

14 Example... Read part number from data base update repair record on maintenance file....

15 Communicational Cohesion Definition: Module performs a series of actions (a sequence of steps to be followed by the product) and all actions are performed on the same data Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental

16 Example Module determine customer details use customer account no find customer name find customer loan balance return customer name, customer loan balance endmodule

17 Sequential Cohesion The output of one component is the input to another. Occurs naturally in functional programming languages Good situation Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental

18 Informational Cohesion Definition: Module performs a number of actions, each with its own entry point, with independent code for each action, all performed on the same data. Different from logical cohesion –Each piece of code has single entry and single exit –In logical cohesion, actions of module intertwined Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental

19 Functional Cohesion Definition: Every element in the component is essential to the computation. Ideal situation. Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental

20 Examples of Cohesion-1 Function A Function B Function D Function C Function E Coincidental Parts unrelated Function A Function A’ Function A’’ logic Logical Similar functions Time t 0 Time t 0 + X Time t 0 + 2X Temporal Related by time Function A Function B Function C Procedural Related by order of functions

21 Examples of Cohesion-2 Function A part 1 Function A part 2 Function A part 3 Functional Sequential with complete, related functions Function A Function B Function C Communicational Access same data Function A Function B Function C Sequential Output of one is input to another

22 Coupling: Degree of dependence among components No dependencies Loosely coupled-some dependencies Highly coupled-many dependencies High coupling makes modifying parts of the system difficult, e.g., modifying a component affects all the components to which the component is connected.

23 Range of Coupling High Coupling Loose Low Content Common Control Stamp Data Uncoupled

24 Content coupling Definition: Example: –Component directly modifies another’s data –Component refers to local data of another component in terms of numerical displacement –Component modifies –another’s code, e.g., jumps into the middle of a routine High Coupling Loose Low Content Common Control Stamp Data Uncoupled

25 Example of Content Coupling Part of program handles lookup for customer. When customer not found, component adds customer by directly modifying the contents of the data structure containing customer data.

26 Example of Content Coupling Part of program handles lookup for customer. When customer not found, component adds customer by directly modifying the contents of the data structure containing customer data. Improvement:

27 Common Coupling Definition: –Global data structures –Common blocks Usually a poor design choice because –Lack of clear responsibility for the data –Reduces readability –Difficult to determine all the components that affect a data element (reduces maintainability) –Difficult to reuse components –Reduces ability to control data accesses High Coupling Loose Low Content Common Control Stamp Data Uncoupled

28 Example Each source process writes directly to global data store. Each sink process reads directly from global data store. Process control component maintains current data about state of operation. Gets data from multiple sources. Supplies data to multiple sinks.

29 Example Each source process writes directly to global data store. Each sink process reads directly from global data store. Improvement Process control component maintains current data about state of operation. Gets data from multiple sources. Supplies data to multiple sinks.

30 Control Coupling Definition: May be either good or bad, depending on situation. –Bad when component must be aware of internal structure and logic of another module –Good if parameters allow factoring and reuse of functionality High Coupling Loose Low Content Common Control Stamp Data Uncoupled

31 Example Acceptable: Module p calls module q and q passes back flag that says it cannot complete the task, then q is passing data Not Acceptable: Module p calls module q and q passes back flag that says it cannot complete the task and, as a result, writes a specific message.

32 Stamp Coupling Definition: Component passes a data structure to another component that does not have access to the entire structure. Requires second component to know how to manipulate the data structure (e.g., needs to know about implementation) May be necessary due to efficiency factors: this is a choice made by insightful designer, not lazy programmer. High Coupling Loose Low Content Common Control Stamp Data Uncoupled

33 Example The print routine of the customer billing accepts a customer data structure as an argument, parses it, and prints the name, address, and billing information. Customer billing system

34 Example The print routine of the customer billing accepts a customer data structure as an argument, parses it, and prints the name, address, and billing information. Improvement Customer Billing System

35 Data Coupling Definition: Two components are data coupled if there are homogeneous data items. Every argument is simple argument or data structure in which all elements are used Good, if it can be achieved. Easy to write contracts for this and modify component independently. High Coupling Loose Low Content Common Control Stamp Data Uncoupled

36 Key Idea in Object-Oriented Programming Object-oriented designs tend to have low coupling.

37 Problem: Classify cohesion for each module Input control items, add the items, and verify totals. Initialize sums and open files. Print transaction and copy transaction to tape. Open files, obtain first transaction and first master record, and print page headings. Update record on file and get next transaction. Produce either a sales report, a project status report, or a customer transaction report. Check syntactic correctness of vehicle guidance parameters.

38 p q t r s u Aircraft typeStatus flag List of aircraft parts 3Function code List of aircraft parts 5Part numberPart manufacturer 6Part numberPart name No. In Out Interface Description p, t, u access the same database in update mode Problem: Define coupling between pairs of modules.

39 qrstu p --- q r s t ---- Coupling between pairs of modules

40 In Class P1: What is the effect of cohesion on maintenance? P2: What is the effect of coupling on maintenance? P3: Produce an example of each type of cohesion. Justify your answers. P4: Produce an example of each type of coupling. Justify your answers. P5: Is there a tradeoff between cohesion and coupling? Justify your answer.