Topic 4 Flashcards
Module Coupling & Cohesion in Practice
Describe the relationship between programming concepts and module concepts.
Programming concepts such as parameters, data types, and functions are closely related to module concepts, as they define how modules interact, share data, and maintain functionality.
Explain how language features can enhance module coupling and cohesion.
Language features such as parameter passing, encapsulation, and data hiding can improve module coupling by reducing dependencies and enhancing cohesion by ensuring that modules have a clear and focused purpose.
Define a parameter in the context of programming.
A variable that is given a constant value for a specified application, used to pass values between software modules, and can take a range of values defined by a set.
How does passing parameters by value affect coupling?
Passing parameters by value generally reduces coupling because each function receives a copy of the data, preventing changes within the function from affecting the original data.
What is the impact of passing parameters by value on cohesion?
Passing parameters by value does not directly impact cohesion but helps maintain the integrity of functions, which can indirectly support better cohesion by keeping data handling localized.
Explain the concept of passing parameters by reference.
Passing parameters by reference allows a function to access and modify the original data directly, which can increase coupling as changes in one part of the code can affect other parts.
Describe an example of passing an integer by value in C++.
In C++, passing an integer by value to a function means that the function works with a copy of the integer, ensuring that any modifications made inside the function do not affect the original integer.
How can programming techniques improve module coupling and cohesion?
Programming techniques such as using clear interfaces, encapsulation, and proper parameter passing can enhance module coupling by minimizing dependencies and improve cohesion by ensuring that modules are focused on specific tasks.
Describe the impact of passing parameters by reference on coupling.
Passing parameters by reference can increase coupling because the function or method has direct access to the original data. Changes made to the data within the function affect the original data, creating a tighter connection between the function and the caller.
Explain how passing parameters by reference can affect cohesion.
Passing by reference does not inherently affect cohesion, but it allows for more efficient data handling, especially for large data structures. This can support better cohesion if the function’s purpose is to update or modify the data directly.
Define the scope in software design.
Software scope is a well-defined boundary that encompasses all the activities done to develop and deliver the software product, identifying what the product will do and what it will not do.
How do global variables differ from local variables in programming?
Global variables can be accessed by two or more non-nested modules without being explicitly passed as parameters, while local variables can only be accessed within the module or routine in which they are declared.
Describe the role of programming techniques in software development.
Programming techniques relate to the way you structure and organize the code, as well as the choices you make about control flow and data.
*Repetition/Decision
*Recursion
*Flowchart: Control; Data; Functional
Explain the concept of recursion in programming.
Recursion is a programming technique where a function calls itself in order to solve a problem, typically breaking it down into smaller, more manageable sub-problems.
What is the significance of flowcharts in programming?
Flowcharts are used to visually represent the control flow of a program, helping to organize and structure the logic of the code.
Describe the relationship between language features and programming techniques.
Language features relate and interact with programming techniques, allowing for stronger control over how programmers work with modules.
Explain the impact of static variables on coupling and cohesion.
Static variables increase coupling due to shared state across instances or function calls and can potentially decrease cohesion if used for unrelated global state management.
Define global variables and their effect on program structure.
Global variables increase coupling by being accessible from any part of the program and decrease cohesion by mixing global state management with module responsibilities.
How do local variables influence coupling and cohesion in software design?
Local variables reduce coupling by limiting visibility to a specific scope and improve cohesion by keeping data management localized to specific functions or blocks.
What is the general recommendation regarding the use of static and global variables in software design?
It is generally advisable to minimize the use of static and global variables to reduce coupling and improve modularity.
Explain the preferred variable type for maintaining clear functionality within modules.
Local variables are preferred for maintaining clear and focused functionality within individual modules or functions, thereby enhancing cohesion.
Describe the potential consequences of using global variables in a program.
Using global variables can lead to increased coupling and decreased cohesion, making the program harder to manage and understand.
How do static variables affect the management of state in a program?
Static variables can lead to shared state across instances or function calls, which can complicate state management and increase coupling.