The goal of Appaserver's developers is to achieve the development standard established by Glenford J. Myers *. Myers ranked the idea of module cohesion the degree of interaction within a model. Myers also ranked the idea of module coupling the degree of interaction between modules.
The quality of a module's function determines the level of cohesion. From worst to best, here are the levels of cohesion:
Modules interact with each other via function calls, passing information back and forth. The degree of information passing sets the level of coupling. From worst to best, here are the levels of coupling:
The ideal function should have only input parameters and return a single value. However, for CPU efficiency, sometimes it is necessary to return multiple values. If multiple return values are necessary, pass the address of the variables to the function starting at the first parameter position.
The developers of Appaserver
attempt to achieve Functional Cohesion and Data Coupling with the
construction of Abstract Data Types (ADT). Each object is represented
with a data structure, and all of the corresponding operations are
contained in the same source file. Moreover, the syntax for each operation is
ObjectName_SomeVerbPhrase_ReturnDatatype( parameter list );
For example:
/* firm.h */ /* ------ */ #ifndef FIRM_H #define FIRM_H typedef struct { char *firm_name; /* Firm's other attributes */ int firm_zip_code; } FIRM; /* Operations */ /* ---------- */ FIRM *firm_new_firm( char *firm_name, int firm_zip_code ); double firm_get_distance_miles_double( int firm_zip_code, int residential_zip_code ); #endif /* firm.c */ /* ------ */ #include "stdio.h" #include "firm.h" FIRM *firm_new_firm( char *firm_name, int firm_zip_code ) { FIRM *firm = (FIRM *)calloc( 1, sizeof( FIRM ) ); if ( !firm ) { fprintf(stderr, "ERROR in %s/%(): cannot allocate %s bytes of memory.\n", __FILE__, __FUNCTION__, sizeof( FIRM ) ); exit( 1 ); } firm->firm_name = firm_name; firm->firm_zip_code = firm_zip_code; return firm; } double firm_get_distance_miles_double( int firm_zip_code, int residential_zip_code ) { double miles_double; miles_double = /* code to compute distance between two zip codes */ return miles_double; } /* main.c */ /* ------ */ #include "stdio.h" #include "firm.h" int main( int argc, char **argv ) { FIRM *firm = firm_new_firm( "Acme Retailer", 33014 ); printf( "Got distance = %lf\n", firm_get_distance_miles_double( firm->firm_zip_code, 95825 ) ); return 0; }
|