L14: Coupling, Cohesion, Visibility Dependency Coupling Internal data coupling Global data coupling Control (or sequence) coupling Component coupling Parameter.

Slides:



Advertisements
Similar presentations
Chapter 5 Inheritance. Objectives Introduction, effects, and benefits of inheritance Base class and derived class objects Base class and derived class.
Advertisements

Quality of a Class Abstraction: Coupling & Cohesion Michael L. Collard, Ph.D. Department of Computer Science Kent State University.
Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
1 Chapter 11 Introducing the Class Pages ( )
1 C++ string Class Chapter 6. 2 Agenda String Basics (cin, getline )  string operations mixed I/O using >> & getline() Table Output using setw() Functions.
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)
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.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
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.
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
CS 2511 Fall UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
INTRODUCTION TO PROGRAMMING STRUCTURE Chapter 4 1.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Coupling and Cohesion Source:
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-3 Cohesion.
Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part V: Design The Design Workflow Design Classes Refining Analysis Relationships.
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.
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.
Object Interconnections CMPS Object Interconnections Past few chapters: focused on individual classes in isolation or classes in parent/child relationships.
Software Design Deriving a solution which satisfies software requirements.
1 COSC3557: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University.
Software Design Process A solution to satisfy the requirements ◦ Design process and methods ◦ Design strategies including object-oriented design and functional.
1 Software Design Overview Reference: Software Engineering, by Ian Sommerville, Ch. 12 & 13.
Concepts of Software Quality Yonglei Tao 1. Software Quality Attributes  Reliability  correctness, completeness, consistency, robustness  Testability.
Cohesion and Coupling CS 4311
Coupling & Cohesion CMSC 201- Fall '11. Vocabulary Routine- A programming unit that performs a task, such as a function, procedure, method, or main class.
© 2005 Prentice Hall9-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
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.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
Lecture 13 Law of Demeter. Cohesion Cohesion: the “glue” that holds a module together. Don’t do things that do not support a common goal Cohesion: the.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Jump to first page (C) 1998, Arun Lakhotia 1 Design Quality Metrics Arun Lakhotia University of Southwestern Louisiana Po Box Lafayette, LA 70504,
Chapter 12 Object-oriented design for more than one class.
Evaluating an Object-Oriented Design ©SoftMoore ConsultingSlide 1.
CSCI-383 Object-Oriented Programming & Design Lecture 24.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Key Principles of Software Architecture and Design (II) adapted from Dave Penny’s.
Review of Function Overloading Allows different functions to have the same name if they have different types or numbers of arguments, e.g. int sqr(int.
Rohini Sharma Roll No. RA1809A01 Regd. No M.Tech.(CSE) Part Time 3 rd Semester.
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.
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.
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.
7. Modular and structured design
Coupling and Cohesion Rajni Bhalla.
OOP Course - Virtual Trip
Coupling and Cohesion 1.
Software Design Mr. Manoj Kumar Kar.
Class and Method Design
Cohesion and Coupling Chapter 5, Pfleeger 01/01/10.
Chapter 4 Procedural Methods.
Improving the Design “Can the design be better?”
CS223: Software Engineering
Object-Oriented Programming
Chapter 09 – Part I Creating High-Quality Code
Software Design Lecture : 9.
Chapter 7 Procedural Methods.
Communication between modules, cohesion and coupling
Design Module view What module should the system and which have to be developed . It determines the module structure of components.
Cohesion and Coupling.
Presentation transcript:

L14: Coupling, Cohesion, Visibility Dependency Coupling Internal data coupling Global data coupling Control (or sequence) coupling Component coupling Parameter coupling Subclass coupling Cohesion Coincidental cohesion Logical cohesion Temporal cohesion Communication cohesion Sequential cohesion Functional cohesion Data cohesion Visibility: visibility & access and friends Chapter 23 of Budd

Dependency If an object cannot meaningfully exist without another object, it is said to be dependent on the second object. Eg a child class is almost always dependent on its parent.

Coupling Strength of interaction between objects. Internal data coupling Global data coupling Control (or sequence) coupling Component coupling Parameter coupling Subclass coupling

Internal Data Coupling class Sneaky { public: void sneak(){ luke->father=darth; }; private: Luke *luke; }; class Luke { public: Luke() { father = anakin; }; string father; };

Global Data Coupling Two or more classes are bound together by their reliance on common global data structures double todaysDow; class One { public: void setDow(){ todaysDow=10534; } }; class Two { public: void printDow(){ cout << todaysDow; } };

Global Data Coupling File scope: names are defined outside blocks or classes. Namespace scope: names are defined within a namespace block. Function scope: labels are the only names that have function scope. They can be used anywhere within a function, but are not accessible outside that function. Class scope : names of class members have class scope. Prototype scope: names declared in a function prototype are visible only until the end of the prototype.

Control Coupling When one class must perform operations in a fixed order, but the order is controlled elsewhere class MyClass { public: void doFirst(){...}; void doSecond(){...}; void do(int option) { switch(option) { case 1: doFirst(); break; case 2: doSecond(); break; default: break; }

Component Coupling One class maintains a data field or value which is an instance of another class. Ideally this relationship should be one way. class Set {... private: List data; };

Parameter Coupling When one class must invoke routines from another via parameters. class MyClass { public: void doSomething(Set aSet){... } };

Subclass Coupling Describes the relationship between a class and its parent. class Parent {...}; class Child: public Parent {...};

Rules to Reduce Coupling Always access data members through accessor methods. E.g., getFather, setFather. Advantages? Within a class method only access: –arguments –instance variables –local variables Try to reduce the number of classes each class knows about. Use namespaces for global data (scope reduction).

Cohesion Degree to which the tasks performed by a single module are functionally related Coincidental cohesion Logical cohesion Temporal cohesion Communicational cohesion Sequential cohesion Functional cohesion Data cohesion

Coincidental Cohesion Elements of a class are grouped for no apparent reason. A class consists of methods that are not related. Usually a sign of poor design.

Logical Cohesion Occurs when there is logical connection among the elements of the class but no actual connection in either data or control. E.g., a library of mathematical functions

Temporal Cohesion Elements are bound together because they all must be used at approximately the same time. E.g., a class that performs program initialisation.

Communicational cohesion Methods are grouped together because they all access the same input/output data or device. The class acts as a device manager. E.g., a Proxy class

Sequential Cohesion Elements are linked by the necessity to be activated in a particular order. Often used to attempt to avoid sequential coupling.

Functional Cohesion A highly cohesive function: a function only performs one task. Very desirable form of cohesion, and highly reusable.

Data Cohesion A class defines a set of data values and exports routines that manipulate the data structure. The embodiment of an ADT E.g., vector, list etc

Visibility An object is visible in a certain context if its name is legal and denotes the object. I.e., the object is in scope.

Access and Visibility class Sneaky { private: int safe; public: Sneaky(){safe=10;}; int &sorry(){return safe;}; print(){cout << safe << endl;} }; Sneaky x; x.sorry() = 1; x.print(); // safe=1 int y = x.sorry(); y = 2; x.print(); // safe=1 int &z = x.sorry(); z = 3; x.print(); // safe=3

Friends C++ has a notion of friend functions and classes. A friend function is a function that can access a classes private parts. Can be useful but easily abused!

Example I: Function as Friend class Vector; // Forward declaration of class Vector class Matrix { float data[4][4]; public: friend Vector operator*(const Matrix&, const Vector&); }; class Vector { float data[4]; public: friend Vector operator*(const Matrix&, const Vector&); } Vector operator*(const Matrix& m, const Vector& v);

Example II: Class as Friend class X; // Forward declaration of class X class F { public: void f_print(X& x); }; class X { int a, b; friend class F; public: X() : a(1), b(2) { } }; void F::f_print(X& x) { cout << "a is " << x.a << endl; cout << "b is " << x.b << endl; } int main() { X xobj; F fobj; fobj.f_print(xobj); }

References Farrell, J. (2009) Object-Oriented Programming Using C++. 4 th ed. MSDN (2009). Visual C++ Language Reference: Scope.