CSC/ECE 517 Fall 2012/ch1b: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Created page with "Cohesion is the "glue" that holds a module together. It can be thought of as the type of association among the component elements of a module. Cohesion is related to the Single R...")
 
No edit summary
 
Line 1: Line 1:
Cohesion is the "glue" that holds a module together. It can be thought of as the type of association among the component elements of a module. Cohesion is related to the Single Responsibility Principle. Generally, one wants the highest level of cohesion possible. An object with high cohesion is defined for one purpose and it performs only that purpose. An object with low cohesion tends to try to do a lot of different things. For example, if there is a Card object which is responsible for drawing itself, sending messages back to the server, and also executing game logic then it has low cohesion because that one class is attempting to do too much. A system can also have low cohesion if too many objects are attempting to do the same thing. For example, if a system has objects to implement a NetRunner game and every card has a unique class with a rendering method and that method is nearly identical in all classes, then the system has low cohesion. A good software design is always designed to achieve high cohesion. An example of a high cohesive EmailMessage class is given below [1].
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).

Latest revision as of 00:04, 23 October 2012

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).