CSC/ECE 517 Summer 2008/wiki2 6 cc: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
 
(47 intermediate revisions by 2 users not shown)
Line 3: Line 3:


==Introduction==
==Introduction==
Cohesion is a measure of how strongly-related and focused the various responsibilities of a software module are. It is usually expressed as “high” or “low” cohesion when being discussed. High cohesion is desired because it is robust, reliable, reusable and more understandable whereas low cohesion has the opposite of those traits – difficult to maintain, test,reuse and understand. With high cohesion comes low coupling. Coupling is the degree of dependence of   internal implementation between different modules – low coupling is where the module doesn't depend on what other module's internal implementation does thus a change in them won't affect the module whereas high coupling is where a change in one module might “break” other modules because they are highly dependent on eachother's internal implementations. This page will show you different types of cohesion and coupling and examples showing the “big picture” of them.  
[http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29 Cohesion] and [http://en.wikipedia.org/wiki/Coupling_%28computer_science%29 Coupling] are concepts often discussed when referring to [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming]. In fact, one of the primary goals of object-oriented programming is “to build highly cohesive classes and to maintain loose coupling between those classes” [http://javaboutique.internet.com/tutorials/coupcoh/]. This begs the question as to what is meant by cohesive classes and how do we know when classes are highly cohesive?   Further, what does loose coupling mean and how do we know it has been maintained? This article combines information and examples gathered from the Web in an effort to shed some light on these very relevant questions.
 
In the first section of this article, we provide the basic definition of cohesion along with examples that describe the different types of cohesion.  Next, we explain the concept of coupling and use more examples to illustrate the different types of coupling.  In the third section of this article, we highlight some of the concepts related to cohesion and coupling, including ways to measure both and an illustration of [http://en.wikipedia.org/wiki/Law_of_Demeter Demeter’s Law].  Lastly, we provide a conclusion to the topics discussed herein.


== Cohesion ==
== Cohesion ==


Cohesion is categorized in “high” and “low” but it is “measured” by how strongly-related or focused the responsibilities are for the class. In a highly-cohesive system, code readability and reusability is increased while complexity is kept manageable. A class of high cohesiveness could decrease its “cohesiveness” by carrying out more varied activities that have little in common and increasing complexity.
[http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29 Cohesion] refers to the degree that a [http://en.wikipedia.org/wiki/Module_%28programming%29 module] performs one and only one function.  In this context, a module refers to any logical collection of “program entities” [http://www.cs.kent.edu/~jmaletic/cs63901/downloads/CouplingCohesion.pdf]. This logical collection of program entities could be a [http://en.wikipedia.org/wiki/Function_%28computer_science%29 function], a [http://en.wikipedia.org/wiki/Class_%28computer_science%29 class], or even a [http://en.wikipedia.org/wiki/Software_package_%28programming%29  package].  As stated earlier, the goal of object-oriented programming is to achieve highly cohesive classes.  High cohesion is desired because it increases the likelihood that a module will be comprehendible, reliable, robust, and reusable [http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29]. Alternatively, a module that exemplifies low cohesion is difficult to comprehend, costly to maintain, and less likely to be reused [http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29]. The following examples illustrate the different types of cohesion and are arranged from lowest (least desirable) to highest (most desirable).


=== Types of Cohesion ===
=====Coincidental Cohesion=====
The types below are in order from "Highest" to "Lowest"
Coincidental cohesion describes a module whose operations are unrelated to one another and the module itself can be used to achieve several different types of tasks.  The following example illustrates coincidental cohesion [http://blogs.ittoolbox.com/eai/implementation/archives/design-principles-cohesion-16069].


=====Functional Cohesion=====
  public static class BackendService {
Functional cohesion describes a module that is designed to perform one and only one taskA functionally cohesive module may contain multiple methods, but all of these methods are designed to help the user achieve a single task.  The following example illustrates functional cohesion.
    public static float computeNetPay(int orderId) {
      // implementation
    }
   
    public static float calculateInventoryReorderAmount(int inventoryId) {
      // implementation
    }
 
    public static boolean generateInvoice(int invoiceId) {
      // implementation
    }
   
    // ...
  }
 
In this example, the <code>BackendService</code> provides a one stop shop for many different types of tasks.  This type of cohesion is the least desirable and should be avoided.
 
=====Logical Cohesion=====
Logical cohesion describes a module that groups operations because categorically they are related but the operations themselves are quite differentTypically, these modules accept a control flag which indicates which operation to execute.  The following example illustrates logical cohesion.


   public class Stack
   public class DataStore {
  {
     public void SaveData(int destination, byte[] data) {
     public Stack()  
      switch (destination) {
    {
        default:
       // implementation
        case 0:
          SaveToDb(data)
          break;
       
        case 1:
          SaveToFile(data)
          break;
       
        case 2:
          SaveToWebService(data)
          break;
       }
     }
     }
      
      
     public void push(Object obj)
     protected void SaveToDb(byte[] data) {
    {
       // implementation
       // implementation
     }
     }
      
      
     public Object pop()
     protected void SaveToFile(byte[] data) {
    {
       // implementation
       // implementation
     }
     }
      
      
     public int getSize()
     protected void SaveToWebService(byte[] data) {
    {
       // implementation
       // implementation
     }
     }
   }
   }
 
=====Sequential Cohesion=====
Sequential cohesion describes modules whose operations are intended to executed in sequence with the output of each operation providing input to the subsequently executed operation.  The following example illustrates sequential cohesion [1].


  class Cube {
In this example, although all of the operations are logically related by the fact that they all save data, the truth is they are in fact quite different. Saving to a database likely requires a completely different implementation than saving to a file or web service.
      public ArrayList getInfo(){
              ArrayList tempList = new ArrayList();
              tempList.add(getArea());
              tempList.add(getVolume());
              return tempList;
      }
      public double getArea(){return 6*side*side;}
      public double getVolume(){return side*side*side;}
    }


===== Information cohesion =====
=====Temporal Cohesion=====
Information cohesion can do several things with the same data - a class with various methods using same data.
Temporal cohesion describes a module that has several operations grouped by the fact that the operations are executed within temporal proximity. The following example illustrates temporal cohesion.


    class Circle {
  public class Startup {
          double radius;      
    public void Initialize() {
          public double getArea(){return 3.14*radius*radius;}
      InitializeLogging();
          public double getDiameter(){return 2 * radius;}
     
          public double getCircumference(){return 3.14*2*radius;}
      InitializeUI();
    }
     
=====Communicational Cohesion=====
      InitializeDb();
Communicational cohesion describes modules that perform multiple operations on the same input or output data [1].  The following example illustrates communication cohesion [2].
    }
 
   
  public class CustomerInformation
     public void InitializeLogging() {
  {
     public CustomerInformation(int accountNum)
    {
       // implementation
       // implementation
     }
     }
      
      
     public String getName()
     public void InitializeUI() {
    {
       // implementation
       // implementation
     }
     }
      
      
     public float getBalance()
     public void InitializeDb() {
    {
       // implementation
       // implementation
     }
     }
   
    // ...
   }
   }
This example highlights a common implementation pattern where tasks are grouped simply by the fact that they need to be executed at around the same time.  Aside from needing to be executed at the same time, these operations implement tasks that are indeed quite different.


=====Procedural Cohesion=====
=====Procedural Cohesion=====
Procedural cohesion is similar to sequential cohesion in that the operations exposed are typically grouped because they are executed within a sequence.  Unlike sequential cohesion however, the operations within a procedurally cohesive module can be somewhat unrelated and output from one operation is not necessarily use as input to a following operation.  The following example illustrates procedural cohesion.
Procedural cohesion describes a module whose operations are typically grouped because they are executed within a sequence.  Unlike sequential cohesion (discussed below), the operations within a procedurally cohesive module can be somewhat unrelated and output from one operation is not necessarily used as input to a subsequently executed operation.  The following example illustrates procedural cohesion.


   public class Student
   public class GradeBookSystem {
  {
     public void Login(int teacherId) {
     public Student(int studentId)
    {
       // implementation
       // implementation
     }
     }
      
      
     public void LoadStudent()
     public ArrayList GetStudents(int teacherId) {
    {
       // implementation
       // implementation
     }
     }
      
      
     public void UpdateGrades(int[] grades)
     public void UpdateGrades(ArrayList grades) {
    {
       // implementation
       // implementation
     }
     }
      
      
     public void UpdateAttendance(Date[] dates)
     public void UpdateAttendance(ArrayList dates) {
    {
       // implementation
       // implementation
     }
     }
      
      
     public void SaveStudent()
     public void Logout(int teacherId) {
    {
       // implementation
       // implementation
     }
     }
   }
   }


=====Temporal Cohesion=====
In this example, the <code>GradeBookSystem</code> exposes different tasks that allow the teacher to login, track student grades/attendance and logout.  These operations are grouped in a procedurally cohesive manner to facilitate the higher level task of upgrading the teacher's grade book.
Temporal cohesion describes a module that has several operations grouped by the fact that the operations are executed within temporal proximity.  The following example illustrates temporal cohesion.
 
=====Communicational Cohesion=====
Communicational cohesion describes modules that perform multiple operations on the same input or output data.  The following example illustrates communication cohesion.


   public class Startup
   public class CustomerInformation {
  {
     public CustomerInformation(int accountNum) {
     public void InitializeLogging()
    {
       // implementation
       // implementation
     }
     }
      
      
     public void InitializeUI()
     public String getName() {
    {
       // implementation
       // implementation
     }
     }
      
      
     public void InitializeDb()
     public float getBalance() {
    {
       // implementation
       // implementation
     }
     }
   
    // ...
   }
   }


=====Logical Cohesion=====
In this example, the <code>getName</code> and <code>getBalance</code> operations facilitate tasks against the common input <code>accountNum</code>.
Logical cohesion describes a module that groups operations because categorically they are related but the operations themselves are quite different.  Typically, these modules accept a control flag which indicates which operation to execute.  The following example illustrates logical cohesion [2].
 
===== Information cohesion =====
Communicational cohesion describes modules that perform several tasks against a shared data structure.  The following example illustrates information cohesion.


   public class DataStore
   class RectangleTransformer {
   {
    
     public void SaveData(int destination, byte[] data)
     Rectangle rectangle;
     {
      
      switch (destination)
    public RectangleTransformer(Rectangle rectangle) {
       {
       this.recentangle = rectangle;
        default:
    }
        case 0:
 
          SaveToDb(data)
    public double getArea() {
          break;
      // implementation
       
    }
        case 1:
 
          SaveToFile(data)
    public double getPermiter() {
          break;
      // implementation
       
    }
        case 2:
 
          SaveToWebService(data)
    public void flip() {
          break;
       // implementation
       }
     }
     }
      
      
     protected void SaveToDb(byte[] data)
     public void stretch(double width, double height) {
     {
      // implementation
     }
  }
 
In this example, all of the <code>RectangleTransformer</code> operations are performing actions against the shared <code>rectangle</code> member variable.
 
=====Functional Cohesion=====
Functional cohesion describes a module that is designed to perform one and only one task.  A functionally cohesive module may contain multiple methods, but all of these methods are designed to help the user achieve a single task.  The following example illustrates functional cohesion.
 
  public class Stack {
    public Stack() {
       // implementation
       // implementation
     }
     }
      
      
     protected void SaveToFile(byte[] data)
     public void push(Object obj) {
    {
       // implementation
       // implementation
     }
     }
      
      
     protected void SaveToWebService(byte[] data)
     public Object pop() {
    {
       // implementation
       // implementation
     }
     }
   }
    
 
     public Object peek() {
=====Coincidental Cohesion=====
Coincidental cohesion describes a module whose operations are unrelated to one another and the module itself can be used to achieve several different types of tasks.  typically used to accomplish several unrelated tasks.  The following example illustrates coincidental cohesion [1].
 
  public static class Math
  {
     public static int Add(int a, int b)
    {
       // implementation
       // implementation
     }
     }
      
      
     public static int Subtract(int a, int b)
     public int isEmpty() {
    {
       // implementation
       // implementation
     }
     }
   
    // ...
   }
   }


===Advantages and disadvantages===
In this example, all of the operations in the <code>Stack</code> class facilitate the task of supporting a Stack data structure.


Cohesion is the idea that the module does a single task - be it calculating data, checking file etc. The "single task mindedness" drastically reduces codes breaking when other modules are changed. If the module uses data from multiple other modules - if even one module changes or breaks, this module might need to be changed thus more time wasted. With single task modules, individual modules can be changed with very little problem.
===Advantages and Disadvantages===
Cohesion is the idea that the module does a single task - be it calculating data, checking file etc. The "single task mindedness" drastically reduces code breaking when other modules are changed. If the module uses data from multiple other modules - if even one module changes or breaks, this module might need to be changed thus more time wasted. With single task modules, individual modules can be changed with very little problem.


==Coupling==
==Coupling==
 
[http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29 Coupling] refers to the degree of connectedness between two modules.  Modules that have many connections between them are said to be highly or tightly coupled. Alternatively, modules that have very little connection between them are said to be lowly or loosely coupled. Introducing more coupling between modules, increases the interdependencies between modules.  As a result, attempting to reuse one module requires the “import” of all of its associated or coupled modules [http://www.site.uottawa.ca:4321/oose/coupling.html].  In addition, high coupling may introduce issues with code reuse, maintenance, testing, and comprehension of the relationships between modules [http://en.wikipedia.org/wiki/Coupling_%28computer_science%29]. For these reasons, it is important to maintain loose coupling between classes. The following examples illustrate the different types of coupling and are arranged from tightest (least desirable) to loosest (most desirable).
Coupling is categorized low (loose and weak) or high(tight and strong). Low coupling is a relationship where one module interacts with another module through a stable interface and does not need to be concerned with other module's implementation. With low coupling, a change in one module will not require changes in the implementation of another module (since they are not dependent of each other). High coupling introduces problems like one module change into multiple module changes, difficulty of understanding the relationships and difficulty of testing and reusing individual modules because of high dependence. Low coupling facilitates high cohesion and vice versa. Low coupling may also reduce performance, and a highly-coupled system is sometimes desirable to achieve maximum efficiency.
 
===Types of coupling===
The types below are ordered from highest to lowest coupling.


=====Content coupling=====  
=====Content coupling=====  
Content coupling is when one module modifies or relies on the internal workings of another module. Therefore changing the way the second module produces data will lead to changing the dependent module.  
Content coupling occurs when one or more modules access the internals of another module. The following example illustrates content coupling.


    class Circle {
  public class Rectangle {
        public double getAreaDifference() { return getArea()-  square.getArea();}
 
    public int Top = 0;
    public int Left = 0;
    public int Width = 0;
    public int Height = 0;
   
    public Rectangle(int top, int left, int width, int height) {
      this.Top = top;
      this.Left = left;
      this.Width = width;
      this.Height = Height;
    }
   
    public int getArea() {
      return this.Width * this.Height;
     }
     }
  }


     class Square {
  public class FloorPlan {
        public String getArea() { //was double getArea()
     Rectangle rectangle = null;
            return area;  
 
        }
    public FloorPlan(int width, int height) {
      rectangle = new Rectangle(0, 0, 50, 100);
    }
 
    public void modifyDimensions(int width, int height) {
      rectangle.Width = width;
      rectangle.Height = height;
    }
   
    public int getArea() {
      return rectangle.getArea();
     }
     }
Notice how the Square's getArea() was double but now changed to String. Now class Circle will get error because of incompatible types.  
  }
 
In this example, <code>FloorPlan</code> is able to directly modify the <code>Width</code> and <code>Height</code> fields of the <code>Rectangle</code> object. This coupling creates a dependency from <code>FloorPlan</code> on the internals of the <code>Rectangle</code> object that inhibits maintenance of the <code>Rectangle</code> class.  If someone wanted to go back and change the <code>Width</code> and <code>Height</code> fields of <code>Rectangle</code> class to use a different data type they would also have to update the <code>FloorPlan</code> class.  


=====Common coupling=====  
=====Common coupling=====  
Common coupling is when two modules share the same global variable.Changing the shared resource implies changing all the modules using it.  
Common coupling occurs when two or more modules modify the same same global variable. The following example illustrates common coupling.


    class Circle{
  #include <stdio.h>
         String radius;//was double radius;
  #include <string.h>
        public double getArea() {return 3.14*radius*radius;}
 
        public double getCircumference() {return 2*3.14*radius;}
  #define NUM_FIELDS 3
    }
 
Notice how the radius was double but now String. Now the getArea() and getCircumference() methods will break because the global variables they both use has been changed.
  class EmployeeRecordParser {
    public:
      EmployeeRecordParser(char* strRow, int nFields) : m_nCount(nFields), m_aryFields(0) {
 
        m_aryFields = new char*[m_nCount];
 
        char* strField = strtok(strRow, ",");
   
        for (int ct = 0; ct < m_nCount && strField; ++ct) {
 
          m_aryFields[ct] = new char[strlen(strField) + 1];
          memcpy(m_aryFields[ct], strField, strlen(strField));
 
          m_aryFields[ct][strlen(strField)] = 0;
 
          strField = strtok(NULL, ",");
        }
      }
 
      ~EmployeeRecordParser() {
         if (m_aryFields)
          delete [] m_aryFields;
      }
 
      int GetCount() { return m_nCount; }
      char* operator[](int nIndex) { return GetField(nIndex); }
      char* GetField(int nIndex) { return nIndex < m_nCount ? m_aryFields[nIndex] : ""; }
 
    private:
      char** m_aryFields;
      int m_nCount;
  };
 
  void ParseRecords(char* strFile) {
    int nRecords = 0;
    char* strRow = strtok(strFile, "\n");
 
    while (strRow) {
 
      EmployeeRecordParser record(strRow, NUM_FIELDS);
 
      printf("\nEmployee Record %d\n------------------------\n", ++nRecords);
 
      for (int i = 0; i < record.GetCount(); ++i)  {
        printf("Field %d: %s\n", i, record[i]);
      }
 
      strRow = strtok(NULL, "\n");
    }
  }
 
  int main() {
    char str[] = "Tom,Frank,919-777-2333\nMikel,Dundlin,919-234-5512\nRobert,Skoglund,919-232-2904";
 
    ParseRecords(str);
 
    return 0;
  }


In the C++ example above, both the <code>ParseRecords</code> method and the <code>EmployeeRecordParser</code> class make use of the globally accessible [http://www.cplusplus.com/reference/clibrary/cstring/strtok.html strtok] function.  Internally, <code>strtok</code> uses a static variable to track the position of the current string being tokenized, which is also used to determine when the whole string has been parsed.  In this particular example, the coupling on this common function has a side effect that causes a bug that prevents all the records from being correctly parsed.


=====Control coupling=====  
=====Control coupling=====  
Control coupling is one module controlling the logic of another, by passing it information on what to do.
Control coupling occurs when one module controls the execution flow of another module.  The following example [http://it.toolbox.com/blogs/enterprise-solutions/design-principles-coupling-data-and-otherwise-16061] illustrates control coupling.
 
  enum InfoType { id, name, balance }
 
  public class CustomerInfo {
    public Object getCustomerInfo(InfoType type) {
      Object returnVal = null;
      switch (infoType) {
        case InfoType.id:                   
          returnVal = getCustomerId();
          break;
 
        case InfoType.name:
          returnVal = getCustomerName();
          break;
 
        case InfoType.balance:
          returnVal = getCustomerBalance();
          break;
      }
     
      return returnVal;     
    }
 
    // ...
  }


    class FileController {
  public class Client {
        public void checkFile(File file) {
    private customerInfo = new CustomerInfo();
            if (file.size() >5000000)//5 megabytes 
 
                processFile(true);
    public void execute() {
            else processFile(false);
      int id = (int)customerInfo.getCustomerInfo(InfoType.id);
        }
      // ...
    }
  }


        public void processFile(boolean delete) {
In this example, the <code>Client</code> class controls the flow of execution within the <code>CustomerInfo</code> module.  This form of coupling requires modules calling <code>CustomerInfo</code> to know about the flow of execution within its class.
            if (delete)
                deleteFile();     
            else
                closeFile();
        }
      }
This Class basically checks the file size and if it is over 5 megs it will tell processFile(boolean) to delete it, else it will close the file. So checkFile(File) is controlling processFile(boolean).


=====Stamp coupling=====
=====Stamp coupling=====
Stamp coupling is when modules share a composite data structure and use only a part of it, possibly a different part. This may lead to changing the way a module reads a record because a field, which the module doesn't need, has been modified.  
Stamp coupling occurs when two or more modules access or modify the same data of a shared object. The following example illustrates stamp coupling.


    class CarInfo {
  public class Customer {
          String carType;
    private int id = 0;
          int numberOfWheels;
    private String name = "";
          double weight;
    private float balance = 0.0f;
      }
 
    public int getId() { return id; }
 
    public void setId(int _id) { id = _id; }
 
    public String getName() { return name; }
 
    public void setName(String _name) { name = _name; }
 
    public float getBalance() { return balance; }
 
    public void setBalance(float _balance) { balance = _balance; }
  }


    class WeightStation {
  public class CustomerInfo() {
      public checkWeight(CarInfo carInfo) {
    public void save(Customer customer) {
          if (carInfo.getWeight >4000)  
      int id = customer.getId();
                System.out.println("car over weight limit");
      String name = gustomer.getName();
          else
      // ...
            System.out.println("car ok");
      }
     }
     }
WeightStation only needs carweight but if CarInfo ever changes its data and WeightStation happens to want to use something else errors could occur.
  }


=====Data coupling=====
  public class Client {
Data coupling is when modules share data through, for example, parameters. Each datum is an elementary piece, and these are the only data which are shared.
    private customerInfo = new CustomerInfo();
 
    public void execute() {
      Customer customer = new Customer();
 
      customer.setId(5);
      customer.setName("Example");
      customer.setBalance(100f);
     
      customerInfo.save(customer);
    }
  }


      Public double calculateRoot(int value) {
In this example, the <code>Client</code> and <code>CustomerInfo</code> classes share the common <code>Customer</code> class. This is a desired form of coupling.
          return value^(1/2);
      }
   
=====Message coupling=====
This is the loosest type of coupling. Modules are not dependent on each other, instead they use a public interface to exchange parameter-less messages.


      class superclass {
=====Data coupling=====
          public void processData(){ module1.processData();}
Data coupling occurs when one module passes primitive type or simple data structure to another module as an argument. The following example illustrates data coupling.
        }
      public Module2 {
          public void doSomething() { superclass.processData();}}


  public class CustomerInfo
  {
    public float getCustomerBalance(int customerId)
    {
      // implementation details
    }
  }
   
  public class Client
  {
    private customerInfo = new CustomerInfo();
   
    public void execute(int customerId)
    {
        float balance = customerInfo.getCustomerBalance(customerId);
 
        // ...   
    }
  }


=====No coupling=====
In this example, <code>Client</code> and <code>CustomerInfo</code> interact using only primitive types of data.  This is a desired form of coupling.
Modules do not communicate at all with one another.


===Advantages and disadvantages===
===Advantages and disadvantages===
Coupling allows interaction between different modules so more complicated tasks can be done. However, a strong coupling will decrease the flexibility of the modules and it will be harder to main and understand. If coupling is too tight, changing one module might have a "snowball effect" and will require changes of other modules that are dependent on it. Coupling must be used with caution and modules must use exactly what it needs and nothing more.
Coupling allows interaction between different modules so more complicated tasks can be done. However, a strong coupling will decrease the flexibility of the modules and it will be harder to main and understand. If coupling is too tight, changing one module might have a "snowball effect" and will require changes of other modules that are dependent on it. Coupling must be used with caution and modules must use exactly what it needs and nothing more.


==Coupling and Cohesion review==
==Related Concepts==
Coupling and Cohesion goes hand in hand. On one hand cohesion wants modules to do exactly a single task thus reduces problems and making a module handle itself. Coupling is inevitably used by cohesion to complete tasks and thus could introduce problems. So good programming desires high cohesion and low coupling - modules that does one task without affecting other modules while at the sametime use as less data/objects from other modules as possible to have low coupling.
When researching cohesion and coupling there are some related concepts that repeatedly appear. Below we discuss some related concepts to cohesion and coupling.  
 
====Measuring Cohesion====
The goal of well-designed systems is to have highly cohesive modules.  Below are three metrics that can be used to determine the level of cohesion within a system.
 
'''Lack of Cohesion 1 (LCOM1)'''
  LCOM1 = (P > Q) ? (P – Q) : 0
 
  P = Total number of method pairs that do not use a common field of the class.
  Q = Total number of method pairs that access at least one common field of the class.


Lower LCOM1 values indicate higher cohesion and better overall design.


==Related Concepts==
'''Lack of Cohesion 2 (LCOM2)'''
  LCOM2 = 1 – sum(mA)/(m*a)
 
  m = Total number of methods in the class.
  a = Total number of attributes in the class.
  mA = Total number of methods that access attribute a.
  sum(mA) = Sum of all mA for all attributes of the class.
 
Lower LCOM2 values indicate higher cohesion and better overall design.  If the total number of methods or attributes is zero than the value of LCOM2 is undefined.
 
'''Lack of Cohesion 3 (LCOM3)'''
 
  LCOM3 = (m – sum(mA)/a) / (m – 1)
 
  m = Total number of methods in the class.
  a = Total number of attributes in the class.
  mA = Total number of methods that access attribute a.
  sum(mA) = Sum of all mA for all attributes of the class.


====Measuring Cohesion====
LCOM3 values greater than one indicates low cohesion and should be addressed.  If the total number of methods is less than two or the number of attributes is zero than the value of LCOM3 is undefined.


====Measuring Coupling====
====Measuring Coupling====
While it is impossible to avoid some level of coupling within systems, the goal is to reduce coupling as much as possible.  Below are three metrics that can be used to determine the level of coupling within a system.
'''Coupling Between Objects (CBO)'''
  CBO = sum(t)
 
  t = Total number of types that are referenced by a particular class, not including any possible super-classes,
  primitive types or common framework classes.
Lower CBO values indicate lower coupling.
'''Data Abstraction Coupling (DAC)'''
  DAC = sum(a)
 
  a = Total number of types that are used for attribute declarations, not including primitive types, common framework classes,
  or types that are inherited from any possible super-classes.
Lower DC values indicate lower coupling.
'''Method Invocation Coupling (MIC)'''
  MIC = nMIC / (N – 1)
 
  N = Total number of classes defined within the project.
  nMIC = Total number of classes that receive a message from the target class.
Lower MIC values indicate lower coupling.


====Demeter's Law====
====Demeter's Law====
[http://en.wikipedia.org/wiki/Law_of_Demeter Demeter's Law] is a design principle that when applied to object-oriented programming means that object A can reference object B but object A cannot use object B to reference object C.  Complying with this principle prevents object A from knowing that object B uses object C thereby reducing coupling.  If object A needs to access a function of object C then it is up to object B to expose an operation encapsulating the reference to object C.  The following example [http://javaboutique.internet.com/tutorials/coupcoh/index-2.html] illustrates how this could be done.
  public float calculateTotal(Order order) {
    return order.getProducts().getTotalCost();
  }
In the example object the object which implements <code>calculateTotal()</code> is calling <code>getTotalCost</code> on a <code>Products</code> object which is exposed through <code>order</code>.  An alternative to this approach would be for the order object to expose this functionality as suggested by the following example.
  public float calculateTotal(Order order) {
    return order.getTotalCost()
  }
 
  public class Order {
    // ...
 
    public float getTotalCost() {
      return products.getTotalCost();
    }
   
    // ...
  }
==Conclusion==
Within this article, we have discussed the basic premise of cohesion and provided examples that illustrate the varying degrees of cohesion.  By creating modules that are highly cohesive, programmers can prevent costly maintenance, while increasing the readability, reliability, and reusability of their code.  Often related to the concept of cohesion is coupling, which we also discussed.  Coupling also has varying degrees and we illustrated each of these using several examples.  By reducing coupling between modules, programmers can encourage code reuse as well as simplify maintenance and testing of their software.  It is important to consider the relationship between these two similar concepts.  As mentioned in the introduction, the goal of object-oriented programming is to have highly cohesive, loosely coupled classes.  Applying loose coupling will often promote high cohesion and creating highly cohesive modules will often result in loose coupling [http://en.wikipedia.org/wiki/Coupling_(computer_science)].  Experience tells us, however, that it is not always possible to achieve the highest degree of cohesion and the lowest degree of coupling.  Consequently, good engineers should use metrics to measure the degree of cohesion and coupling in their programs and be familiar with the different types of cohesion and coupling so that they may be successful in achieving one of the primary goals within object-oriented programming.
== See also ==
*[http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29 Wikipedia: Cohesion]
*[http://en.wikipedia.org/wiki/Coupling_%28computer_science%29 Wikipedia: Coupling]
*[http://www.cs.kent.edu/~jmaletic/cs63901/downloads/CouplingCohesion.pdf Software Engineeriing Presentation: Coupling and Cohesion]
*[http://www.frontendart.com/monitor/help/node23.html More Cohesion Metrics]
*[http://www.frontendart.com/monitor/help/node22.html More Coupling Metrics]
*[http://javaboutique.internet.com/tutorials/coupcoh/index-2.html Example: Measuring Coupling and Cohesion]


== References ==
== References ==
# http://blogs.ittoolbox.com/eai/implementation/archives/design-principles-cohesion-16069
#http://javaboutique.internet.com/tutorials/coupcoh/
# http://www.waysys.com/ws_content_bl_pgssd_ch06.html
#http://www.cs.kent.edu/~jmaletic/cs63901/downloads/CouplingCohesion.pdf
# http://www.site.uottawa.ca:4321/oose/index.html#cohesion
#http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29
# http://javaboutique.internet.com/tutorials/coupcoh/index-2.html
#http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29
# http://bmrc.berkeley.edu/courseware/cs169/spring01/lectures/objects/sld001.htm
#http://blogs.ittoolbox.com/eai/implementation/archives/design-principles-cohesion-16069
# http://blogs.ittoolbox.com/eai/implementation/archives/design-principles-coupling-data-and-otherwise-16061
#http://www.site.uottawa.ca:4321/oose/coupling.html
#http://en.wikipedia.org/wiki/Coupling_%28computer_science%29
#http://it.toolbox.com/blogs/enterprise-solutions/design-principles-coupling-data-and-otherwise-16061
#http://javaboutique.internet.com/tutorials/coupcoh/index-2.html
#http://javaboutique.internet.com/tutorials/coupcoh/index-2.html
#http://www.waysys.com/ws_content_bl_pgssd_ch06.html
#http://bmrc.berkeley.edu/courseware/cs169/spring01/lectures/objects/sld001.htm
#http://www.cs.sjsu.edu/faculty/pearce/modules/lectures/ood/metrics/Cohesion.htm
#http://class.ee.iastate.edu/berleant/home/Courses/SoftwareEngineering/CprE486fall2004/designModularity.htm
#http://www.eli.sdsu.edu/courses/spring99/cs535/notes/cohesion/cohesion.html#Heading8
#http://www.site.uottawa.ca:4321/oose/index.html#sequentialcohesion

Latest revision as of 03:25, 8 July 2008

Cohesion and coupling. Cohesion and coupling are concepts that are reasonably easy to understand, but nonetheless, it is worthwhile to gather readable illustrations of where they apply. Browse the hundreds of Web pages that attempt to explain these concepts, picking your favorite examples. Categorize these examples, so that the reader will see the big picture, rather than just a set of redundant illustrations. Many of these pages mention related concepts; list some of them and explain how they relate to cohesion and coupling.


Introduction

Cohesion and Coupling are concepts often discussed when referring to object-oriented programming. In fact, one of the primary goals of object-oriented programming is “to build highly cohesive classes and to maintain loose coupling between those classes” [1]. This begs the question as to what is meant by cohesive classes and how do we know when classes are highly cohesive? Further, what does loose coupling mean and how do we know it has been maintained? This article combines information and examples gathered from the Web in an effort to shed some light on these very relevant questions.

In the first section of this article, we provide the basic definition of cohesion along with examples that describe the different types of cohesion. Next, we explain the concept of coupling and use more examples to illustrate the different types of coupling. In the third section of this article, we highlight some of the concepts related to cohesion and coupling, including ways to measure both and an illustration of Demeter’s Law. Lastly, we provide a conclusion to the topics discussed herein.

Cohesion

Cohesion refers to the degree that a module performs one and only one function. In this context, a module refers to any logical collection of “program entities” [2]. This logical collection of program entities could be a function, a class, or even a package. As stated earlier, the goal of object-oriented programming is to achieve highly cohesive classes. High cohesion is desired because it increases the likelihood that a module will be comprehendible, reliable, robust, and reusable [3]. Alternatively, a module that exemplifies low cohesion is difficult to comprehend, costly to maintain, and less likely to be reused [4]. The following examples illustrate the different types of cohesion and are arranged from lowest (least desirable) to highest (most desirable).

Coincidental Cohesion

Coincidental cohesion describes a module whose operations are unrelated to one another and the module itself can be used to achieve several different types of tasks. The following example illustrates coincidental cohesion [5].

 public static class BackendService {
   public static float computeNetPay(int orderId) {
     // implementation
   }
   
   public static float calculateInventoryReorderAmount(int inventoryId) {
     // implementation
   }
 
   public static boolean generateInvoice(int invoiceId) {
     // implementation
   }
   
   // ...
 }

In this example, the BackendService provides a one stop shop for many different types of tasks. This type of cohesion is the least desirable and should be avoided.

Logical Cohesion

Logical cohesion describes a module that groups operations because categorically they are related but the operations themselves are quite different. Typically, these modules accept a control flag which indicates which operation to execute. The following example illustrates logical cohesion.

 public class DataStore {
   public void SaveData(int destination, byte[] data) {
     switch (destination) {
       default:
       case 0:
         SaveToDb(data)
         break;
       
       case 1:
         SaveToFile(data)
         break;
       
       case 2:
         SaveToWebService(data)
         break;
     }
   }
   
   protected void SaveToDb(byte[] data) {
     // implementation
   }
   
   protected void SaveToFile(byte[] data) {
     // implementation
   }
   
   protected void SaveToWebService(byte[] data) {
     // implementation
   }
 }

In this example, although all of the operations are logically related by the fact that they all save data, the truth is they are in fact quite different. Saving to a database likely requires a completely different implementation than saving to a file or web service.

Temporal Cohesion

Temporal cohesion describes a module that has several operations grouped by the fact that the operations are executed within temporal proximity. The following example illustrates temporal cohesion.

 public class Startup {
   public void Initialize() {
      InitializeLogging();
      
      InitializeUI();
      
      InitializeDb();
   }
   
   public void InitializeLogging() {
     // implementation
   }
   
   public void InitializeUI() {
     // implementation
   }
   
   public void InitializeDb() {
     // implementation
   }
 }

This example highlights a common implementation pattern where tasks are grouped simply by the fact that they need to be executed at around the same time. Aside from needing to be executed at the same time, these operations implement tasks that are indeed quite different.

Procedural Cohesion

Procedural cohesion describes a module whose operations are typically grouped because they are executed within a sequence. Unlike sequential cohesion (discussed below), the operations within a procedurally cohesive module can be somewhat unrelated and output from one operation is not necessarily used as input to a subsequently executed operation. The following example illustrates procedural cohesion.

 public class GradeBookSystem {
   public void Login(int teacherId) {
     // implementation
   }
   
   public ArrayList GetStudents(int teacherId) {
     // implementation
   }
   
   public void UpdateGrades(ArrayList grades) {
     // implementation
   }
   
   public void UpdateAttendance(ArrayList dates) {
     // implementation
   }
   
   public void Logout(int teacherId) {
     // implementation
   }
 }

In this example, the GradeBookSystem exposes different tasks that allow the teacher to login, track student grades/attendance and logout. These operations are grouped in a procedurally cohesive manner to facilitate the higher level task of upgrading the teacher's grade book.

Communicational Cohesion

Communicational cohesion describes modules that perform multiple operations on the same input or output data. The following example illustrates communication cohesion.

 public class CustomerInformation {
   public CustomerInformation(int accountNum) {
     // implementation
   }
   
   public String getName() {
     // implementation
   }
   
   public float getBalance() {
     // implementation
   }
   
   // ...
 }

In this example, the getName and getBalance operations facilitate tasks against the common input accountNum.

Information cohesion

Communicational cohesion describes modules that perform several tasks against a shared data structure. The following example illustrates information cohesion.

 class RectangleTransformer {
 
   Rectangle rectangle;
   
   public RectangleTransformer(Rectangle rectangle) { 
     this.recentangle = rectangle; 
   }
 
   public double getArea() {
     // implementation 
   }
 
   public double getPermiter() {
     // implementation 
   }
 
   public void flip() {
     // implementation 
   }
   
   public void stretch(double width, double height) {
     // implementation 
   }
 }

In this example, all of the RectangleTransformer operations are performing actions against the shared rectangle member variable.

Functional Cohesion

Functional cohesion describes a module that is designed to perform one and only one task. A functionally cohesive module may contain multiple methods, but all of these methods are designed to help the user achieve a single task. The following example illustrates functional cohesion.

 public class Stack {
   public Stack() {
     // implementation
   }
   
   public void push(Object obj) {
     // implementation
   }
   
   public Object pop() {
     // implementation
   }
 
   public Object peek() {
     // implementation
   }
   
   public int isEmpty() {
     // implementation
   }
 }

In this example, all of the operations in the Stack class facilitate the task of supporting a Stack data structure.

Advantages and Disadvantages

Cohesion is the idea that the module does a single task - be it calculating data, checking file etc. The "single task mindedness" drastically reduces code breaking when other modules are changed. If the module uses data from multiple other modules - if even one module changes or breaks, this module might need to be changed thus more time wasted. With single task modules, individual modules can be changed with very little problem.

Coupling

Coupling refers to the degree of connectedness between two modules. Modules that have many connections between them are said to be highly or tightly coupled. Alternatively, modules that have very little connection between them are said to be lowly or loosely coupled. Introducing more coupling between modules, increases the interdependencies between modules. As a result, attempting to reuse one module requires the “import” of all of its associated or coupled modules [6]. In addition, high coupling may introduce issues with code reuse, maintenance, testing, and comprehension of the relationships between modules [7]. For these reasons, it is important to maintain loose coupling between classes. The following examples illustrate the different types of coupling and are arranged from tightest (least desirable) to loosest (most desirable).

Content coupling

Content coupling occurs when one or more modules access the internals of another module. The following example illustrates content coupling.

 public class Rectangle {
 
   public int Top = 0;
   public int Left = 0;
   public int Width = 0;
   public int Height = 0;
   
   public Rectangle(int top, int left, int width, int height) {
     this.Top = top;
     this.Left = left;
     this.Width = width;
     this.Height = Height;
   }
    
   public int getArea() {
     return this.Width * this.Height;
   }
 }
 public class FloorPlan {
   Rectangle rectangle = null;
 
   public FloorPlan(int width, int height) {
     rectangle = new Rectangle(0, 0, 50, 100);
   }
 
   public void modifyDimensions(int width, int height) {
     rectangle.Width = width;
     rectangle.Height = height;
   }
   
   public int getArea() {
     return rectangle.getArea();
   }
 }

In this example, FloorPlan is able to directly modify the Width and Height fields of the Rectangle object. This coupling creates a dependency from FloorPlan on the internals of the Rectangle object that inhibits maintenance of the Rectangle class. If someone wanted to go back and change the Width and Height fields of Rectangle class to use a different data type they would also have to update the FloorPlan class.

Common coupling

Common coupling occurs when two or more modules modify the same same global variable. The following example illustrates common coupling.

 #include <stdio.h>
 #include <string.h>
 
 #define NUM_FIELDS 3
 
 class EmployeeRecordParser {
   public:
     EmployeeRecordParser(char* strRow, int nFields) : m_nCount(nFields), m_aryFields(0) {
 
       m_aryFields = new char*[m_nCount];
 
       char* strField = strtok(strRow, ",");
   
       for (int ct = 0; ct < m_nCount && strField; ++ct) {
 
          m_aryFields[ct] = new char[strlen(strField) + 1];

          memcpy(m_aryFields[ct], strField, strlen(strField));
 
          m_aryFields[ct][strlen(strField)] = 0;
 
          strField = strtok(NULL, ",");
       }
      }
  	
     ~EmployeeRecordParser() {
        if (m_aryFields)			
          delete [] m_aryFields;
      }
 
      int GetCount() { return m_nCount; }
      char* operator[](int nIndex) { return GetField(nIndex); }
      char* GetField(int nIndex) { return nIndex < m_nCount ? m_aryFields[nIndex] : ""; }
  
    private:
      char**	m_aryFields;
      int	m_nCount;
 };
 void ParseRecords(char* strFile) {
   int nRecords = 0;
   char* strRow = strtok(strFile, "\n");
 
   while (strRow) {		
 
     EmployeeRecordParser record(strRow, NUM_FIELDS);
 
     printf("\nEmployee Record %d\n------------------------\n", ++nRecords);
 
     for (int i = 0; i < record.GetCount(); ++i)  {
       printf("Field %d: %s\n", i, record[i]);
     }
 
     strRow = strtok(NULL, "\n");
   }
 }
 
 int main() {
   char str[] = "Tom,Frank,919-777-2333\nMikel,Dundlin,919-234-5512\nRobert,Skoglund,919-232-2904";
 
   ParseRecords(str);
  
   return 0;
 }

In the C++ example above, both the ParseRecords method and the EmployeeRecordParser class make use of the globally accessible strtok function. Internally, strtok uses a static variable to track the position of the current string being tokenized, which is also used to determine when the whole string has been parsed. In this particular example, the coupling on this common function has a side effect that causes a bug that prevents all the records from being correctly parsed.

Control coupling

Control coupling occurs when one module controls the execution flow of another module. The following example [8] illustrates control coupling.

 enum InfoType { id, name, balance }
 
 public class CustomerInfo {
   public Object getCustomerInfo(InfoType type) {
     Object returnVal = null;
     switch (infoType) {
       case InfoType.id:                    
         returnVal = getCustomerId();
         break;
 
       case InfoType.name:
         returnVal = getCustomerName();
         break;
 
       case InfoType.balance:
         returnVal = getCustomerBalance();
         break;
     }
     
     return returnVal;      
   }
 
   // ...
 }
 public class Client {
   private customerInfo = new CustomerInfo();
 
   public void execute() {
     int id = (int)customerInfo.getCustomerInfo(InfoType.id);
     // ...
   }
 }

In this example, the Client class controls the flow of execution within the CustomerInfo module. This form of coupling requires modules calling CustomerInfo to know about the flow of execution within its class.

Stamp coupling

Stamp coupling occurs when two or more modules access or modify the same data of a shared object. The following example illustrates stamp coupling.

 public class Customer {
   private int id = 0;
   private String name = "";
   private float balance = 0.0f;
 
   public int getId() { return id; }
 
   public void setId(int _id) { id = _id; }
 
   public String getName() { return name; }
 
   public void setName(String _name) { name = _name; }
 
   public float getBalance() { return balance; }
 
   public void setBalance(float _balance) { balance = _balance; }
 }
 public class CustomerInfo() {
   public void save(Customer customer) {
     int id = customer.getId();
     String name = gustomer.getName();
     // ...
   }
 }
 public class Client {
   private customerInfo = new CustomerInfo();
 
   public void execute() {
     Customer customer = new Customer();
 
     customer.setId(5);
     customer.setName("Example");
     customer.setBalance(100f);
     
     customerInfo.save(customer);
   }
 }

In this example, the Client and CustomerInfo classes share the common Customer class. This is a desired form of coupling.

Data coupling

Data coupling occurs when one module passes primitive type or simple data structure to another module as an argument. The following example illustrates data coupling.

 public class CustomerInfo
 {
   public float getCustomerBalance(int customerId)
   {
     // implementation details
   }
 }
   
 public class Client
 {
   private customerInfo = new CustomerInfo();
   
   public void execute(int customerId)
   {
       float balance = customerInfo.getCustomerBalance(customerId);
 
       // ...    
   }
 }

In this example, Client and CustomerInfo interact using only primitive types of data. This is a desired form of coupling.

Advantages and disadvantages

Coupling allows interaction between different modules so more complicated tasks can be done. However, a strong coupling will decrease the flexibility of the modules and it will be harder to main and understand. If coupling is too tight, changing one module might have a "snowball effect" and will require changes of other modules that are dependent on it. Coupling must be used with caution and modules must use exactly what it needs and nothing more.

Related Concepts

When researching cohesion and coupling there are some related concepts that repeatedly appear. Below we discuss some related concepts to cohesion and coupling.

Measuring Cohesion

The goal of well-designed systems is to have highly cohesive modules. Below are three metrics that can be used to determine the level of cohesion within a system.

Lack of Cohesion 1 (LCOM1)

 LCOM1 = (P > Q) ? (P – Q) : 0
 
 P = Total number of method pairs that do not use a common field of the class.
 Q = Total number of method pairs that access at least one common field of the class.

Lower LCOM1 values indicate higher cohesion and better overall design.

Lack of Cohesion 2 (LCOM2)

 LCOM2 = 1 – sum(mA)/(m*a)
 
 m = Total number of methods in the class.
 a = Total number of attributes in the class.
 mA = Total number of methods that access attribute a.
 sum(mA) = Sum of all mA for all attributes of the class.

Lower LCOM2 values indicate higher cohesion and better overall design. If the total number of methods or attributes is zero than the value of LCOM2 is undefined.

Lack of Cohesion 3 (LCOM3)

 LCOM3 = (m – sum(mA)/a) / (m – 1)
 
 m = Total number of methods in the class.
 a = Total number of attributes in the class.
 mA = Total number of methods that access attribute a.
 sum(mA) = Sum of all mA for all attributes of the class.

LCOM3 values greater than one indicates low cohesion and should be addressed. If the total number of methods is less than two or the number of attributes is zero than the value of LCOM3 is undefined.

Measuring Coupling

While it is impossible to avoid some level of coupling within systems, the goal is to reduce coupling as much as possible. Below are three metrics that can be used to determine the level of coupling within a system.

Coupling Between Objects (CBO)

 CBO = sum(t)
 
 t = Total number of types that are referenced by a particular class, not including any possible super-classes, 
 primitive types or common framework classes.

Lower CBO values indicate lower coupling.

Data Abstraction Coupling (DAC)

 DAC = sum(a)
 
 a = Total number of types that are used for attribute declarations, not including primitive types, common framework classes, 
 or types that are inherited from any possible super-classes.

Lower DC values indicate lower coupling.

Method Invocation Coupling (MIC)

 MIC = nMIC / (N – 1)
 
 N = Total number of classes defined within the project.
 nMIC = Total number of classes that receive a message from the target class.

Lower MIC values indicate lower coupling.

Demeter's Law

Demeter's Law is a design principle that when applied to object-oriented programming means that object A can reference object B but object A cannot use object B to reference object C. Complying with this principle prevents object A from knowing that object B uses object C thereby reducing coupling. If object A needs to access a function of object C then it is up to object B to expose an operation encapsulating the reference to object C. The following example [9] illustrates how this could be done.

 public float calculateTotal(Order order) {
    return order.getProducts().getTotalCost();
 }

In the example object the object which implements calculateTotal() is calling getTotalCost on a Products object which is exposed through order. An alternative to this approach would be for the order object to expose this functionality as suggested by the following example.

 public float calculateTotal(Order order) {
   return order.getTotalCost()
 }
 
 public class Order {
   // ...
 
   public float getTotalCost() {
     return products.getTotalCost();
   }
   
   // ...
 }

Conclusion

Within this article, we have discussed the basic premise of cohesion and provided examples that illustrate the varying degrees of cohesion. By creating modules that are highly cohesive, programmers can prevent costly maintenance, while increasing the readability, reliability, and reusability of their code. Often related to the concept of cohesion is coupling, which we also discussed. Coupling also has varying degrees and we illustrated each of these using several examples. By reducing coupling between modules, programmers can encourage code reuse as well as simplify maintenance and testing of their software. It is important to consider the relationship between these two similar concepts. As mentioned in the introduction, the goal of object-oriented programming is to have highly cohesive, loosely coupled classes. Applying loose coupling will often promote high cohesion and creating highly cohesive modules will often result in loose coupling [10]. Experience tells us, however, that it is not always possible to achieve the highest degree of cohesion and the lowest degree of coupling. Consequently, good engineers should use metrics to measure the degree of cohesion and coupling in their programs and be familiar with the different types of cohesion and coupling so that they may be successful in achieving one of the primary goals within object-oriented programming.

See also

References

  1. http://javaboutique.internet.com/tutorials/coupcoh/
  2. http://www.cs.kent.edu/~jmaletic/cs63901/downloads/CouplingCohesion.pdf
  3. http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29
  4. http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29
  5. http://blogs.ittoolbox.com/eai/implementation/archives/design-principles-cohesion-16069
  6. http://www.site.uottawa.ca:4321/oose/coupling.html
  7. http://en.wikipedia.org/wiki/Coupling_%28computer_science%29
  8. http://it.toolbox.com/blogs/enterprise-solutions/design-principles-coupling-data-and-otherwise-16061
  9. http://javaboutique.internet.com/tutorials/coupcoh/index-2.html
  10. http://javaboutique.internet.com/tutorials/coupcoh/index-2.html
  11. http://www.waysys.com/ws_content_bl_pgssd_ch06.html
  12. http://bmrc.berkeley.edu/courseware/cs169/spring01/lectures/objects/sld001.htm
  13. http://www.cs.sjsu.edu/faculty/pearce/modules/lectures/ood/metrics/Cohesion.htm
  14. http://class.ee.iastate.edu/berleant/home/Courses/SoftwareEngineering/CprE486fall2004/designModularity.htm
  15. http://www.eli.sdsu.edu/courses/spring99/cs535/notes/cohesion/cohesion.html#Heading8
  16. http://www.site.uottawa.ca:4321/oose/index.html#sequentialcohesion