CS 696: Advanced OO
| References | 1 |
| Cohesion | 2 |
| ...Coincidental | 4 |
| ...Logical | 5 |
| ...Temporal | 6 |
| ...Procedural | 8 |
| ...Communication | 9 |
| ...Sequential | 10 |
| ...Functional | 11 |
| ...Informational Strength | 12 |
| Object Cohesion | 13 |
| ...Individual Objects | 16 |
"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. Generally, one wants the
highest level of cohesion possible."
Bergland, 1981
"A software component is said to exhibit a high degree of
cohesion if the elements in that unit exhibit a high degree of
functional relatedness. This means that each element in
the program unit should be essential for that unit to achieve
its purpose."
Sommerville, 1989
Coincidental (worst)
Logical
Temporal
Procedural
Communication
Sequential
Functional (best)
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}
}Similar to control coupling
Cure:
Isolate each function into separate operations
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;
}
}Common example:
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";
}
}
| [Macintosh] EquationWindow=146,171,406,661 SpacingWindow=0,0,0,0
| [General] Zoom=200 CustomZoom=150 ShowAll=0 Version=2.01 OptimalPrinter=1 MinRect=0 ForceOpen=0 ToolbarDocked=1 ToolbarShown=1 ToolbarDockPos=1 [Fonts] Text=Times Function=Times Variable=Times,I LCGreek=Symbol,I UCGreek=Symbol Symbol=Symbol Vector=Times,B Number=Times
[Sizes] |
Call these constructors/destructors from a
nonobject-oriented routine that performs a single, cohesive
task
Procedural modules are application specific
In context the module seems reasonable
Removed from the context these modules seem strange and very hard to understand
Makes module hard to modify, understand
Class Builder verse Program writer
Cure:
Cure:
Isolate each element into a separate modules
Rarely occurs in object-oriented systems due to
polymorphism
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:
Decompose into smaller modules
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:
"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:
Evaluating cohesion requires:
Does the object directly correspond to a "real world entity," physical or logical?
Is the object characterized in very non-specific terms?
If the object ( or system of objects) is removed from the context of the immediate application, does it still represent a coherent and complete object-oriented concept?
Do all the objects directly support, or directly contribute to the support of, the object-oriented concept that the system represents?
Are there missing objects?
Does not discuss non-objects:
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:
What are:
| Constructors | Selectors | Iterators |
| addColumn(Vector) addRow(Vector) setElementAt(Object, int, int)
fromString(String)
setColumnSeperatorChar(...) | columnAt(int) columnsAt(int, int) columnsAt(Object, int) rowAt(int) rowsAt(int, int) rowsAt(Object, int) contains(Object) elementAt(int, int) indexOf(Object)
numberOfColumns()
save(OutputStream, String) | elements() |