160 likes | 265 Views
Hierarchical View of Software Construction. Statements Three Types of Statements Sequence Selection Iteration Modules (paragraph, procedure, subroutine, function) One or more statements combine to form a module Program One or more modules combine to form a program
E N D
Hierarchical View of Software Construction • Statements • Three Types of Statements • Sequence • Selection • Iteration • Modules (paragraph, procedure, subroutine, function) • One or more statements combine to form a module • Program • One or more modules combine to form a program • Sub-System or System • One or more programs combine to form a sub-system or system
Two Software Evaluation Metrics Cohesion Coupling
COHESION: The measure of strength of the interrelatedness of statements within a module • Functional • Informational • Communicational • Procedural • Temporal • Logical • Coincidental High (best) Low (worst)
COHESION: The measure of strength of the interrelatedness of statements within a module • Functional - one action or goal • Informational - multiple independent actions on • the same data • Communicational - series of steps on same data • Procedural - series of steps for an action • Temporal - series of related actions related in time • Logical - series of related actions • Coincidental - multiple, unrelated actions High (best) Low (worst)
Cohesion Generally, the smaller the module the greater the cohesion
Coincidental Cohesion On Form Activate Event: SHOW screen 1.2 PRINT the ssn [global variable] in the SSN picture box Print the name [global variable] in the NAME picture box PRINT column headings ("COURSE ID TITLE LOCATION START TIME DAYS INSTRUCTOR" in the BIG Picture Box FINDFIRST record in the student-class table for the global SSN IF nomatch on student class table PRINT 'no classes' in the picture box ELSE SET counter to 0
LOOP WHILE counter < 15 and nomatch on student-class table is FALSE FINDFIRST record on the class file for the COURSE ID and SECTION on the student class table IF nomatch on class table MSGBOX ("COURSE ID NOT ON THE CLASS TABLE -- should not happen---WHY??”) ELSE FINDFIRST record on the course file for the COURSE ID on the class file IF nomatch on the course file MSGBOX (“Course Id not on course table -- should not happen – why??) SET title to “not found” END IF FINDFIRST INSTRUCTOR SSN [from the class table] on the Instructor Table IF nomatch on the instructor file MSGBOX(“Instructor ssn not on the instructor file”) PRINT course-id, section, title, building, room, start time, days, instructor SSN in the picture box ELSE PRINT course-id, section, title, building, room, start time, days, instructor NAME in picture box END IF ENDIF FINDNEXT record on student class table for the global SSN INCREMENT counter by 1 END LOOP IF counter >= 15 MSGBOX ("picture box is too small to show all classes") END IF END IF
Problems with the Previous Design The loop routine contains many actions or goals a. Obtain the information about the class from the class table b. Obtain the title from the course table c. Obtain the instructor name from the instructor table
Stronger Cohesion • Make Smaller Modules • Make the loop a separate function • Break up the loop into smaller modules • Class information • Course information • Instructor information
On Form Activate Event: SHOW screen 1.2 PRINT the ssn [global variable] in the SSN picture box PRINT the name [global variable] in the NAME picture box PRINT column headings ("COURSE ID LOCATION START TIME DAYS INSTRUCTOR" in the BIG Picture Box FINDFIRST SSN [global variable]in the student-class table IF nomatch on student class table PRINT 'no classes' in the picture box ELSE CALL looping routine ENDIF
Looping Routine: SET counter to 0 LOOP WHILE counter < 15 and nomatch on student-class table is FALSE CALL class routine FINDNEXT SSN [global variable] on student cla INCREMENT counter by 1 END LOOP IF counter >= 15 MSGBOX ("picture box is too small to show all classes") ENDIF End Looping routine
Class Routine FINDFIRST record on the class file for the COURSE ID and SECTION on the student class table IF nomatch on class table MSGBOX ("COURSE ID NOT ON THE CLASS TABLE”) ELSE CALL Course Routine CALL Instructor Routine ENDIF End Class Routine
Instructor Routine FINDFIRST record on the instructor file for the INSTRUCTOR SSN on the class file IF nomatch on the instructor file MSGBOX(“Instructor ssn not on the instructor file”) PRINT course-id, section, building, room, start time, days, instructor SSN in the picture box ELSE PRINT course-id, section, building, room, start time, days, instructor NAME in picture box ENDIF End Instructor Routine
Course Routine FINDFIRST record on the course file for the COURSE ID on the class file IF nomatch on the course file MSGBOX (“Course Id not on course table”) – why??) SET title to “not found” ENDIF End Course Routine
COUPLING: The measure of strength of the connection between modules • Content • Common • Control • Stamp • Data • No Coupling High (worst) Low (best)
COUPLING: The measure of strength of the connection between modules • Content - direct branch into middle of module • Common - global reference of variables • Control - control element being passed • Stamp - pass an entire data structure • Data - variables or fields only being passed • No Coupling High (worst) Low (best)