Sei sulla pagina 1di 3

Lesson 3 Project questions 7, 8, and 10. 7. Why are cohesion and coupling important to programmers?

Dividing solutions into modules is one of the most difficult tasks in solution development. Modules should be able to function independently performing their specified task and connect to other modules in the program through the data needed to execute the program. Cohesion allows the programmer to write a module of a larger program and then gives the programmer the ability to test it independently from the other modules (Sprankle & Hubbard, 2009). Coupling allows all programmers to use the necessary variables from the modules without losing cohesion (Sprankle & Hubbard, 2009). Cohesion and Coupling are valuable tools that allow the programmer to develop a solution quickly and more efficiently.

Works Cited Sprankle, M., & Hubbard, J. (2009). Problem Solving & Programming Concepts. New Jersey: Prentice Hall.

8. How are modules coupled? Modules must be coupled in order for data to flow through the program. Modules are coupled in three ways: global variables, parameters, and return values. Global variables can be seen by all the modules of the program. Global variables must be used cautiously. Global variables do allow data coupling through the entire program, yet defeat one of the purposes of cohesion which is to allow for the duplication of variable names in different modules (Sprankle & Hubbard, 2009). Parameters are another way of enabling coupling that permits the exchange of data between modules. Parameters are local variables that are transferred from one module to another (Sprankle & Hubbard, 2009). A return value is the result of a function. This value is only sent out of the called module into the calling module (Sprankle & Hubbard, 2009). Even though Modules can be coupled in three ways, the preferred methods for coupling modules are parameters, and return values.

Works Cited Sprankle, M., & Hubbard, J. (2009). Problem Solving & Programming Concepts. New Jersey: Prentice Hall.

10. Define the two types of parameters. How do they differ? Under what circumstances would you use each type? There are two ways to send data from one module to another through the use of parameters. The first way is to send the value of the variable while the second is to send the address of the variable. In a call-by-value parameter, only the value of the variable is given as a parameter. When the value in the called module is changed, nothing happens to the variable in the calling module. In a call-by-reference parameter, only the address to the variable is given as a parameter. Anything the called module changes with it, goes right back to the variable in the calling module. A call-by-value parameter will be used to send information into a function that does not have to be returned or passed back from the function. A call-by-reference parameter is used if the function is required to return or pass a value back from the function (Sprankle & Hubbard, 2009). Call-by-value and call-by-reference parameters are hard to understand and the most important concept to understand and to use in programming. They allow programmers to work independently developing smaller sections of a larger program.

Works Cited Sprankle, M., & Hubbard, J. (2009). Problem Solving & Programming Concepts. New Jersey: Prentice Hall.

Potrebbero piacerti anche