CS 635 Advanced Object-Oriented Design & Programming Spring Semester, 2002 Cohesion |
||
---|---|---|
© 2002, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 28-Mar-02 |
Cohesion
"Cohesion is the degree to which the tasks performed by a single module are functionally related."
Types of Module CohesionFrom Worst to Best
Coincidental (worst)
Logical
Temporal
Procedural
Communication
Sequential
Functional (best)
Module Cohesion
Coincidental
Little or no constructive relationship among the elements of the module
Common Object Occurrence:
class Rous { public static int findPattern( String text, String pattern) { // blah} public static int average( Vector numbers ) { // blah} public static OutputStream openFile( String fileName ) { // blah} }
Module Cohesion Logical
Module performs a set of related functions, one of which is selected via function parameter when calling the module
Similar to control coupling
Cure:
public void sample( int flag ) { switch ( flag ) { case ON: // bunch of on stuff break; case OFF: // bunch of off stuff break; case CLOSE: // bunch of close stuff break; case COLOR: // bunch of color stuff break; } }
Module Cohesion Temporal
Elements are grouped into a module because they are all processed within the same limited time period
Common example:
"Initialization" modules that provide default values for objects
"End of Job" modules that clean up
procedure initializeData() { font = "times"; windowSize = "200,400"; foo.name = "Not Set"; foo.size = 12; foo.location = "/usr/local/lib/java"; }
Cure: Each object should have a constructor and destructor
class foo { public foo() { foo.name = "Not Set"; foo.size = 12; foo.location = "/usr/local/lib/java"; } }
Sample Configuration File
[Macintosh] |
[General] |
EquationWindow=146,171,406,661 |
Zoom=200 |
SpacingWindow=0,0,0,0 |
CustomZoom=150 |
|
ShowAll=0 |
|
Version=2.01 |
[Spacing] |
OptimalPrinter=1 |
LineSpacing=150% |
MinRect=0 |
MatrixRowSpacing=150% |
ForceOpen=0 |
MatrixColSpacing=100% |
ToolbarDocked=1 |
SuperscriptHeight=45% |
ToolbarShown=1 |
SubscriptDepth=25% |
ToolbarDockPos=1 |
LimHeight=25% |
|
LimDepth=100% |
[Fonts] |
LimLineSpacing=100% |
Text=Times |
NumerHeight=35% |
Function=Times |
DenomDepth=100% |
Variable=Times,I |
FractBarOver=1pt |
LCGreek=Symbol,I |
FractBarThick=0.5pt |
UCGreek=Symbol |
SubFractBarThick=0.25pt |
Symbol=Symbol |
FenceOver=1pt |
Vector=Times,B |
SpacingFactor=100% |
Number=Times |
MinGap=8% |
|
RadicalGap=2pt |
[Sizes] |
EmbellGap=1.5pt |
Full=12pt |
PrimeHeight=45% |
Script=7pt |
|
ScriptScript=5pt |
|
Symbol=18pt |
|
SubSymbol=12pt |
Module Cohesion Procedural
Associates processing elements on the basis of their procedural or algorithmic relationships
Procedural modules are application specific
In context the module seems reasonable
Removed from the context these modules seem strange and very hard to understand
Module Cohesion Communication
Operations of a module all operate upon the same input data set and/or produce the same output data
Cure:
Module Cohesion Sequential
Sequential association the type in which the output data from one processing element serve as input data for the next processing element
A module that performs multiple sequential functions where the sequential relationship among all of the functions is implied by the problems or application statement and where there is a data relationship among all of the functions
Cure:
Module Cohesion Functional
If the operations of a module can be collectively described as a single specific function in a coherent way, the module has functional cohesion
If not, the module has lower type of cohesion
In an object-oriented system:
Module Cohesion Informational Strength
Myers states:
"The purpose of an informational-strength module is to hide some concept, data structure, or resource within a single module.
An informational-strength module has the following definition:
Object Cohesion
The degree to which components of a class are tied together
Evaluating cohesion requires:
Questions to probe cohesiveness of an object
Does the object represent a complete and coherent concept or does it more closely resemble a partial concept, or a random collection of information?
Does the object directly correspond to a "real world entity," physical or logical?
Is the object characterized in very non-specific terms?
Objects in Isolation
Isolation means without considering any hierarchy that may contain the object or class
Does not discuss non-objects:
Individual Objects
A primitive method is any method that cannot be implemented simply, efficiently, and reliably without knowledge of the underlying implementation of the object
A composite method is any method constructed from two or more primitive methods – sometimes from different objects
A sufficient set of primitive methods for an object is a minimum set of primitive methods to accomplish all necessary work with on the object
A sufficient set of primitive methods has two major problems:
An object is not as cohesive as it could be if the public interface contains:
Composite Objects
A composite object is an object that is conceptually composed of two, or more, other objects, which are externally discernable.
Component objects are those that make up the composite object.
Component objects are externally discernable if
Ranking of Cohesion of Composite ObjectsIncreasing order of Goodness
Accessing Cohesion of an Individual Object
Accessment of the public methods/public non-methods/component objects
Are all the items appropriate for the given object?
Do we have at least a minimally sufficient set of items?
Do we have extra or application-specific items?
Copyright ©, All rights reserved.
2002 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.
Previous    visitors since 28-Mar-02    Next