UHD::CS3320::CHAP61 INTRODUCTION TO OBJECTS Chapter 6.

Slides:



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

Slide 7A.1 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
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.
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)
Slide 7.1 © The McGraw-Hill Companies, 2002 Object-Oriented and Classical Software Engineering Fifth Edition, WCB/McGraw-Hill, 2002 Stephen R. Schach
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
Software Lifecycle A series of steps through which a software product progresses Lifetimes vary from days to months to years Consists of –people –overall.
Lecture 13: Object- Oriented Concepts Anita S. Malik Adapted from Schach (2004) Chapter 7.
ASP.NET Programming with C# and SQL Server First Edition
C++ fundamentals.
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
O BJECT O RIENTATION F UNDAMENTALS Prepared by: Gunjan Chhabra.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Coupling and Cohesion Source:
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,
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-3 Cohesion.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
SOFTWARE DESIGN Design Concepts Design is a meaningful engineering representation of something that is to be built It can be traced to a customer’s requirements.
Concepts of Software Quality Yonglei Tao 1. Software Quality Attributes  Reliability  correctness, completeness, consistency, robustness  Testability.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
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
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.
Dr D. Greer, Queens University Belfast )Chapter Six 1 Software Engineering Chapter Six Software Design Quality Learning Outcomes.
Introduction to Object-Oriented Design Concepts. Object-Oriented Design Overview Object-Oriented design is basically a set of guidelines/concepts for.
Chapter 4 Basic Object-Oriented Concepts. Chapter 4 Objectives Class vs. Object Attributes of a class Object relationships Class Methods (Operations)
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 7: Object-Oriented Design.
Rohini Sharma Roll No. RA1809A01 Regd. No M.Tech.(CSE) Part Time 3 rd Semester.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
Design CS 470 – Software Engineering I Sheldon X. Liang, PH.D.
Lecture 12 Implementation Issues with Polymorphism.
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 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 7.1 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented Software Engineering WCB/McGraw-Hill, 2008 Stephen R.
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.
Cohesion and Coupling Chapter 5, Pfleeger 01/01/10.
CIS 375 Bruce R. Maxim UM-Dearborn
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.
CS223: Software Engineering
Software Design CMSC 345, Version 1/11.
Programming Logic and Design Fourth Edition, Comprehensive
Software Design Lecture : 9.
Object-Oriented and Classical Software Engineering Eighth Edition, WCB/McGraw-Hill, 2011 Stephen R. Schach.
Introduction to Data Structure
Object-Oriented PHP (1)
Cohesion and Coupling.
DESIGN CONCEPTS AND PRINCIPLES
Presentation transcript:

UHD::CS3320::CHAP61 INTRODUCTION TO OBJECTS Chapter 6

UHD::CS3320::CHAP62 WHAT IS A MODULE? A lexically contiguous sequence of program statements, bounded by boundary elements, with aggregate identifier. Methods for breaking up product into modules?

UHD::CS3320::CHAP63 EXAMPLE A computer architect decides to build an ALU, shifter and 16 registers using AND, OR and NOT gates (rather than NAND or NOR gates).

UHD::CS3320::CHAP64

5 COMPUTER DESIGN-- CNTD Computer architect realizes that it is better to build a chip using one type of gates ==> Partitions the system so that one gate type on each chip.

UHD::CS3320::CHAP66 COMPUTER DESIGN-- CNTD Two designs functionally equivalent Second design –hard to understand –hard to locate faults –difficult to extend or enhance –cannot be reused in another product Modules must be selected with –maximal relationships within modules –minimal relationships between modules

UHD::CS3320::CHAP67 COMPOSITE/STRUCTURED DESIGN Method for breaking up product into modules for –maximal relationships within modules –minimal relationships between modules Module cohesion –Degree of interaction within module Module coupling –Degree of interaction between modules

UHD::CS3320::CHAP68 C/SD-- CONTD Module: function, logic, and context A module is identified with its function Example: a module computes square root of double precision integers using Newton’s algorithm Module should be names compute square root

UHD::CS3320::CHAP69 MODULE COHESION Seven categories or levels of cohesion: 1. Coincidental cohesion (worst) 2. Logical cohesionshould be avoided 3. Temporal cohesion 4. Procedural cohesion 5. Communicational cohesion 6. Informational cohesiondesirable 7. Functional cohesion (best)

UHD::CS3320::CHAP Coincidental Cohesion Module performs multiple, completely unrelated actions Example: –Module: print next line, reverse string of characters in second argument, add 7 to third argument, convert fourth argument to floating point Why is Coincidental Cohesion so bad? –Degrades maintainability –No reuse

UHD::CS3320::CHAP Logical Cohesion Module performs series of related actions, each is selected by setting the value of a parameter Example: –Module performs all input and output ops Why is logical Cohesion so bad? –Interface difficult to understand –Code for more than one action may be intertwined –Difficult to reuse

UHD::CS3320::CHAP Temporal Cohesion Module performs a series of actions related in time Example: –open input file, open output file, initialize table of records, read first record (i.e. Initialization actions) Why is temporal cohesion so bad? –Actions weakly related to one another, but strongly related to other actions in other modules

UHD::CS3320::CHAP Procedural cohesion Module performs series of actions related by procedure to be followed in product. Example: –read part number then update repair record Why is procedural cohesion so bad? –Actions still weakly connected, so not reusable.

UHD::CS3320::CHAP Communicational Cohesion Module performs series of actions related by procedure to be followed by product, but in addition all the actions operate on same data Example: –calculate new coordinates and send them to terminal Still lack of reusability

UHD::CS3320::CHAP Informational Cohesion Module performs a number of actions, each with its own entry point, with independent code for each action, all performed on same data structure. This is essentially an Abstract Data Type

UHD::CS3320::CHAP Functional Cohesion Module with functional cohesion performs exactly one action More reusable Maintenance easier

UHD::CS3320::CHAP617 Cohesion Case Study Compute average daily temperatures at various sites.

UHD::CS3320::CHAP618 Cohesion Case Study

UHD::CS3320::CHAP619 Coupling Degree of interaction between modules File categories of coupling ( some goo some bad): 1. Content couplingWorst 2. Common coupling 3. Control coupling 4. Stamp coupling 5. Data couplingBest

UHD::CS3320::CHAP620 Content Coupling One module directly references content of another module. Example: –One module branches into local label of another –One module references local data of another

UHD::CS3320::CHAP621 Common Coupling Two modules are commonly coupled if they have access to global data.

UHD::CS3320::CHAP622 Control Coupling Two modules are control coupled if one passes an element of control to another Example: –Module p calls module q –Module q is supposed count the number of characters in a text file and return the result to module p. –If module q fails (e.g. Can read from file) it return -1. ==> the two modules are data coupled

UHD::CS3320::CHAP623 Control Coupling--Example CNTD Suppose: –Module p calls module q –Module q is supposed count the number of characters in a text file and return the result to module p. –If module q fails (e.g. Can read from file) returns a message that module p is supposed to output. ==> the two modules are control coupled

UHD::CS3320::CHAP624 Control Coupling-- CNTD If q passes information back to p and p decides what actions to take ==> data coupling If q passes information back to p but also informs p what actions to take ==> control coupling What’s so bad about control coupling –module are not independent: module q must know structure and logic of p. –Affects reuse

UHD::CS3320::CHAP625 Stamp Coupling Two modules are stamp coupled if data structure is passed as parameter, but called module operates on some but not all of individual components of data structure. What’s so bad about Stamp coupling –Not clear, without reading entire module which part of data structure is changed –Pass more data than necessary uncontrolled data access can lead to security problems

UHD::CS3320::CHAP626 Data Coupling Two modules are data coupled is all parameters are homogeneous data items (i.e. Simple data items, or data structures all of whose elements are used by called module) Examples: display_time_of_arrival(flight_number) Compute_product(first_num, second_num) get_job_with_highest_priority(job_queue)

UHD::CS3320::CHAP627 Data Coupling-- CNTD Why is data coupling so good? –Difficulties of all other couplings not present –Module interface is explicit –No side effects –Maintenance is easier

UHD::CS3320::CHAP628 Object-Oriented Paradigm Data Encapsulation Information Hiding Inheritance Polymorphism

UHD::CS3320::CHAP629 Data Encapsulation Data structure together with the actions done on those data are encapsulated in the same “module”--the class A class is an Abstract Data Type An object is an instance of a class Why is encapsulation so good? –A class is a module with informational cohesion –functional cohesion: at the method level

UHD::CS3320::CHAP630 UML Representation Short hand notation ClassName Data members Actions ClassName

UHD::CS3320::CHAP631 UML Representation objectName ClassName myHandWatch Watch

UHD::CS3320::CHAP632 Data Encapsulation and Development Data Encapsulation allows abstraction during product analysis and design When extracting and design the classes: –what objects are needed to be modeled? –what are the data attributes of each object? –what actions are to be performed on the data of each object? What are the interactions between objects

UHD::CS3320::CHAP633 Stepwise Refinement Step 1. Design in terms of high level concepts –concern with behavior of data structure Step 2. Design low level components –concern with implementation of the that behavior

UHD::CS3320::CHAP634 Information Hiding Implementation details of the data attributes and methods of a class are hidden from outside the class. Control access to data attributes –thru public methods –private members Why is information hiding good ? –Interaction between classes occurs through explicitly declared interfaces. –No side effects: change in one module does not effect others –I.e. data coupling between classes.

UHD::CS3320::CHAP635 Inheritance Define HumanBeing to be a class A HumanBeing has attributes, such as name, age, height, gender Assign values to attributes when describing object Define Teacher to be a subclass of HumanBeing A Teacher has all attributes if HumanBeing, plus attributes of his/her own (discipline, school, department) A Teacher inherits all attributes of HumanBeing

UHD::CS3320::CHAP636 UML Representation HumanBeingTeacher

UHD::CS3320::CHAP637 Inheritance Inheritance is essential to object-oriented language such as Smalltalk, C++, and JAVA Does it improve cohesion? Coupling? Provides further data abstraction Improves reuse

UHD::CS3320::CHAP638 Composition/Aggregation A class may contain other classes Example: A State contains many Counties which contain many townships A PoliceState is composed of PoliceOfficers A Directory contain Files

UHD::CS3320::CHAP639 UML Representation-- Aggregation StateCountyTownship

UHD::CS3320::CHAP640 Polymorphism Classical paradigm –function sort_integer_list –function sort_float_list –function sort_string_list must explicitly invoke correct version

UHD::CS3320::CHAP641 All that is needed is myList.sort( ) –correct method is invoked dynamically –Method sort() is polymorphic ListClass virtual method sort StringListClass Implementation of method string sort FloatListClass Implementation of method float sort IntListClass Implementation of method integer sort

UHD::CS3320::CHAP642 Summary Objects with high cohesion and low coupling Objects Information Hiding Abstract Data Types Data Encapsulation Modules with high cohesion and low coupling Modules