Slide 7B.31 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.

Slides:



Advertisements
Similar presentations
Quality of a Class Abstraction: Coupling & Cohesion Michael L. Collard, Ph.D. Department of Computer Science Kent State University.
Advertisements

Chapter 11 Component-Level Design
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Slide 7A.1 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
UHD::CS3320::CHAP61 INTRODUCTION TO OBJECTS Chapter 6.
1 From Modules to Objects Xiaojun Qi. 2 What Is a Module? A lexically contiguous sequence of program statements, bounded by boundary elements, with an.
What is an object? Your dog, your desk, your television set, your bicycle. Real-world objects share two characteristics: They all have state and behavior;
Module: Definition ● A logical collection of related program entities ● Not necessarily a physical concept, e.g., file, function, class, package ● Often.
Computer Concepts 5th Edition Parsons/Oja Page 546 CHAPTER 11 Software Engineering Section A PARSONS/OJA Computer Programming.
Slide 7.1 © The McGraw-Hill Companies, 2002 Object-Oriented and Classical Software Engineering Fifth Edition, WCB/McGraw-Hill, 2002 Stephen R. Schach
Slide 1.1 © The McGraw-Hill Companies, 2002 Object-Oriented and Classical Software Engineering Fifth Edition, WCB/McGraw-Hill, 2002 Stephen R. Schach
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Lecture 13: Object- Oriented Concepts Anita S. Malik Adapted from Schach (2004) Chapter 7.
Slide 12E.121 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 11 Slide 1 Architectural Design.
Computers Are Your Future Tenth Edition Chapter 11: Programming Languages & Program Development Copyright © 2009 Pearson Education, Inc. Publishing as.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
COMPUTER SOFTWARE Section 2 “System Software: Computer System Management ” CHAPTER 4 Lecture-6/ T. Nouf Almujally 1.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
CSE 303 – Software Design and Architecture
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.
CSCI 6231 Software Engineering Chapter 7 From Modules to Objects
Slide 7.1 Copyright © 2011 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented and Classical Software Engineering Eighth Edition, WCB/McGraw-Hill,
DESIGN.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
Slide 10.1 Copyright © 2011 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented and Classical Software Engineering Eighth Edition,
SE: CHAPTER 7 Writing The Program
Slide 7.1 © The McGraw-Hill Companies, 2007 Object-Oriented and Classical Software Engineering Seventh Edition, WCB/McGraw-Hill, 2007 Stephen R. Schach.
Cohesion and Coupling CS 4311
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
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.
GRASP: Designing Objects with Responsibilities
Slide 20.1 Copyright © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. An Introduction to Object-Oriented Systems Analysis and Design with.
CS540 Software Design Lecture 3 & 4 1 Lecture 3 & 4: Modularity, Coupling, Cohesion and Abstraction Anita S. Malik Adapted from Schach.
7.1/108 Introduction To Objects 7.2/108 Modules Cohesion and low Coupling Data encapsulation Abstract data types Information hiding Objects Objects with.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Slide 13.1 © The McGraw-Hill Companies, 2002 Object-Oriented and Classical Software Engineering Fifth Edition, WCB/McGraw-Hill, 2002 Stephen R. Schach.
Chapter 4 Software. Chapter 4: Software Generations of Languages Each computer is wired to perform certain operations in response to an instruction. An.
Dr D. Greer, Queens University Belfast )Chapter Six 1 Software Engineering Chapter Six Software Design Quality Learning Outcomes.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
Chapter 14 Programming and Languages McGraw-Hill/Irwin Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved.
Introduction to OOP CPS235: Introduction.
Week 6: Software Design HNDIT Software Engineering Software Design Learning Outcomes  Understand the activities involved in the Design process.
Ch 7: From Modules to Objects (Part Two) CSCI 4320.
Design CS 470 – Software Engineering I Sheldon X. Liang, PH.D.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods.
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.
Slide 13A.1 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
Slide 7.1 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented Software Engineering WCB/McGraw-Hill, 2008 Stephen R.
Visit for more Learning Resources
Coupling and Cohesion Rajni Bhalla.
Coupling and Cohesion 1.
Chapter 3: Using Methods, Classes, and Objects
Object-Oriented and Classical Software Engineering Eighth Edition, WCB/McGraw-Hill, 2011 Stephen R. Schach 1.
Coupling and Cohesion By Bonnie Ngu.
Component-Level Design
Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach
Improving the Design “Can the design be better?”
FROM MODULES TO OBJECTS.
Programming Logic and Design Fourth Edition, Comprehensive
Object-Oriented and Classical Software Engineering Eighth Edition, WCB/McGraw-Hill, 2011 Stephen R. Schach.
Cohesion and Coupling.
DESIGN CONCEPTS AND PRINCIPLES
Presentation transcript:

Slide 7B.31 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach

Slide 7B.32 © The McGraw-Hill Companies, 2005 CHAPTER 7 — Unit B FROM MODULES TO OBJECTS

Slide 7B.33 © The McGraw-Hill Companies, 2005 Continued from Unit 7A

Slide 7B.34 © The McGraw-Hill Companies, 2005 Figure Coupling l The degree of interaction between two modules  Five categories or levels of coupling (non-linear scale)

Slide 7B.35 © The McGraw-Hill Companies, Content Coupling l Two modules are content coupled if one directly references contents of the other l Example 1:  Module p modifies a statement of module q l Example 2:  Module p refers to local data of module q in terms of some numerical displacement within q l Example 3:  Module p branches into a local label of module q

Slide 7B.36 © The McGraw-Hill Companies, 2005 Why Is Content Coupling So Bad? Almost any change to module q, even recompiling q with a new compiler or assembler, requires a change to module p

Slide 7B.37 © The McGraw-Hill Companies, Common Coupling l Two modules are common coupled if they have write access to global data l Example 1  Modules cca and ccb can access and change the value of global_variable Figure 7.9

Slide 7B.38 © The McGraw-Hill Companies, Common Coupling (contd) l Example 2:  Modules cca and ccb both have access to the same database, and can both read and write the same record l Example 3:  FORTRAN common  COBOL common (nonstandard)  COBOL-80 global

Slide 7B.39 © The McGraw-Hill Companies, 2005 Why Is Common Coupling So Bad? l It contradicts the spirit of structured programming  The resulting code is virtually unreadable Figure 7.10

Slide 7B.40 © The McGraw-Hill Companies, 2005 Why Is Common Coupling So Bad? (contd) l Modules can have side-effects  This affects their readability  Example: edit_this_transaction (record_7)  The entire module must be read to find out what it does l A change during maintenance to the declaration of a global variable in one module necessitates corresponding changes in other modules l Common-coupled modules are difficult to reuse

Slide 7B.41 © The McGraw-Hill Companies, 2005 Why Is Common Coupling So Bad? (contd) Common coupling between a module p and the rest of the product can change without changing p in any way  Clandestine common coupling  Example: The Linux kernel l A module is exposed to more data than necessary  This can lead to computer crime

Slide 7B.42 © The McGraw-Hill Companies, Control Coupling l Two modules are control coupled if one passes an element of control to the other l Example 1:  An operation code is passed to a module with logical cohesion l Example 2:  A control switch passed as an argument

Slide 7B.43 © The McGraw-Hill Companies, 2005 Control Coupling (contd) Module p calls module q l Message:  I have failed — data l Message:  I have failed, so write error message ABC123 — control

Slide 7B.44 © The McGraw-Hill Companies, 2005 Why Is Control Coupling So Bad? l The modules are not independent  Module q (the called module) must know the internal structure and logic of module p  This affects reusability l Associated with modules of logical cohesion

Slide 7B.45 © The McGraw-Hill Companies, Stamp Coupling l Some languages allow only simple variables as parameters  part_number  satellite_altitude  degree_of_multiprogramming l Many languages also support the passing of data structures  part_record  satellite_coordinates  segment_table

Slide 7B.46 © The McGraw-Hill Companies, 2005 Stamp Coupling (contd) l Two modules are stamp coupled if a data structure is passed as a parameter, but the called module operates on some but not all of the individual components of the data structure

Slide 7B.47 © The McGraw-Hill Companies, 2005 Why Is Stamp Coupling So Bad? l It is not clear, without reading the entire module, which fields of a record are accessed or changed  Example calculate_withholding (employee_record) l Difficult to understand l Unlikely to be reusable l More data than necessary is passed  Uncontrolled data access can lead to computer crime

Slide 7B.48 © The McGraw-Hill Companies, 2005 Why Is Stamp Coupling So Bad? (contd) l However, there is nothing wrong with passing a data structure as a parameter, provided that all the components of the data structure are accessed and/or changed l Examples: invert_matrix (original_matrix, inverted_matrix); print_inventory_record (warehouse_record);

Slide 7B.49 © The McGraw-Hill Companies, Data Coupling l Two modules are data coupled if all parameters are homogeneous data items (simple parameters, or data structures all of whose elements are used by called module) l Examples:  display_time_of_arrival (flight_number);  compute_product (first_number, second_number);  get_job_with_highest_priority (job_queue);

Slide 7B.50 © The McGraw-Hill Companies, 2005 Why Is Data Coupling So Good? l The difficulties of content, common, control, and stamp coupling are not present l Maintenance is easier

Slide 7B.51 © The McGraw-Hill Companies, Coupling Example Figure 7.11

Slide 7B.52 © The McGraw-Hill Companies, 2005 Coupling Example (contd) l Interface description Figure 7.12

Slide 7B.53 © The McGraw-Hill Companies, 2005 Coupling Example (contd) l Coupling between all pairs of modules Figure 7.13

Slide 7B.54 © The McGraw-Hill Companies, The Importance of Coupling l As a result of tight coupling  A change to module p can require a corresponding change to module q  If the corresponding change is not made, this leads to faults l Good design has high cohesion and low coupling  What else characterizes good design? (see over)

Slide 7B.55 © The McGraw-Hill Companies, 2005 Key Definitions Figure 7.14

Slide 7B.56 © The McGraw-Hill Companies, Data Encapsulation l Example  Design an operating system for a large mainframe computer. Batch jobs submitted to the computer will be classified as high priority, medium priority, or low priority. There must be three queues for incoming batch jobs, one for each job type. When a job is submitted by a user, the job is added to the appropriate queue, and when the operating system decides that a job is ready to be run, it is removed from its queue and memory is allocated to it l Design 1 (Next slide)  Low cohesion — operations on job queues are spread all over the product

Slide 7B.57 © The McGraw-Hill Companies, 2005 Data Encapsulation — Design 1 Figure 7.15

Slide 7B.58 © The McGraw-Hill Companies, 2005 Data Encapsulation — Design 2 Figure 7.16

Slide 7B.59 © The McGraw-Hill Companies, 2005 Data Encapsulation (contd) m_encapsulation has informational cohesion m_encapsulation is an implementation of data encapsulation  A data structure ( job_queue ) together with operations performed on that data structure l Advantages  Development  Maintenance

Slide 7B.60 © The McGraw-Hill Companies, 2005 Data Encapsulation and Development l Data encapsulation is an example of abstraction l Job queue example:  Data structure job_queue  Three new functions initialize_job_queue add_job_to_queue delete_job_from_queue

Slide 7B.61 © The McGraw-Hill Companies, Data Encapsulation and Development l Abstraction  Conceptualize problem at a higher level Job queues and operations on job queues  Not a lower level Records or arrays

Slide 7B.62 © The McGraw-Hill Companies, 2005 Stepwise Refinement 1. Design the product in terms of higher level concepts  It is irrelevant how job queues are implemented 2. Then design the lower level components  Totally ignore what use will be made of them

Slide 7B.63 © The McGraw-Hill Companies, 2005 Stepwise Refinement (contd) l In the 1st step, assume the existence of the lower level  Our concern is the behavior of the data structure job_queue l In the 2nd step, ignore the existence of the higher level  Our concern is the implementation of that behavior l In a larger product, there will be many levels of abstraction

Slide 7B.64 © The McGraw-Hill Companies, Data Encapsulation and Maintenance l Identify the aspects of the product that are likely to change l Design the product so as to minimize the effects of change  Data structures are unlikely to change  Implementation details may change l Data encapsulation provides a way to cope with change

Slide 7B.65 © The McGraw-Hill Companies, 2005 Implementation of Class JobQueue C++ Java Figure 7.17 Figure 7.18

Slide 7B.66 © The McGraw-Hill Companies, 2005 Implementation of queueHandler C++ Java Figure 7.19 Figure 7.20

Slide 7B.67 © The McGraw-Hill Companies, 2005 Data Encapsulation and Maintenance (contd) What happens if the queue is now implemented as a two- way linked list of JobRecord ?  A module that uses JobRecord need not be changed at all, merely recompiled C++ Java Figure 7.22 Figure 7.21

Slide 7B.68 © The McGraw-Hill Companies, 2005 Data Encapsulation and Maintenance (contd) Only implementation details of JobQueue have changed Figure 7.23

Slide 7B.69 © The McGraw-Hill Companies, 2005 Continued in Unit 7C