Introduction to Programming Structures 1

43 Slides || 7 Easy Questions || 11 Intermediate Questions || 0 Hard Questions || 0 Essay Questions



Program Module




Cohesion and Coupling




Lecture Outline "Introduction to Programming structures 1: Modules Cohesion and Coupling Local and Global variables Parameters Return values"




Blank




Learning Objectives "Explain the need for structured programming Explain how to design Modules and functions in terms of Cohesion and Coupling Explain the difference between Local and Global variables. Explain the use of Parameters and Return values"




Blank




Lecture Progress "Introduction to Programming structures 1: Modules Cohesion and Coupling Local and Global variables Parameters Return values"




Blank




Structuring a Computer Program "Modules Self-contained component used in combination with other components Complete program happens by Relationship among Modules through Cohesion Coupling Exchange of Data Global and Local variables Parameters Return Values"




Blank




Lecture Outline "Introduction to Programming structures 1: Modules Cohesion and Coupling Local and Global variables Parameters Return values"




Blank




Modules "Author writing a Text Book Determine Title Break title into Chapters Arrange the Chapters in correct sequence Starts to write"




Blank




Rules for Designing Modules (2 of 5) "Each module has and performs single function For example printing




calculating




Rules for Designing Modules (3 of 5) "Each module is short enough to be easily read and modified when the need arises"




Blank




Rules for Designing Modules (4 of 5) "The length of a module is determined by Its Function What is the purpose of the Module? The Number Of Instructions to be executed to perform that Function"




Blank




Rules for Designing Modules (5 of 5) "A module is developed to control the order of processing. i.e. the overall flow of the Program as stipulated in the Algorithm"




Blank




Types of Modules "Different types of modules are often combined in one solution. The Control Module The Initialization Module The Process Module Calculation or Computation Module Print Module Read and Data Validation Module Wrap-up Module"




Blank




The Control module "The Control module shows the overall flow of the data through the program. All other modules are subordinate to it. It coordinates the Flow of the Overall Program Determines which other module should execute next"




Blank




The Initialization Module "The Initialization module executes instructions that are: Executed Only Once during the program




and only at the Beginning.
For example
Opening files




The Process Module "Process modules may execute only once




or are part of a loop




The Wrap-up Modules "Wrap-up modules process all instructions that are Executed Only Once during the program and only at the End. For example Closing files and printing totals




among others."




Lecture Progress "Introduction to Programming structures 1: Modules Cohesion and Coupling Local and Global variables Parameters Return values"




Blank




Cohesion and Coupling "Recall Solution should be broken into Modules Modules should be functionally independent and perform a single task However




Modules would need to be Connected or Combined to perform larger tasks within the overall program.
This is achieved through Exchange Of Data needed within each Module."




Cohesion "Cohesion is the ability for a module to work independently from all other modules. i.e. Possess it own data entry




printing




Coupling "Coupling allows for the communication between modules. Communication is accomplished by Some type of Interface between modules The Interface enables inter-module data exchanged This exchange has minimum interruption of the modular independence."




Blank




Illustration: Cohesion & Coupling (1 of 2) "If Module1 performs Task1 successfully




Module1 may be required to provide data to Module2.
Cohesion means having separate modules in a program
Module1 and Module2
Coupling means data passing from Module1 to Module2."




Illustration: Cohesion & Coupling (2 of 2) Differences: Cohesion & Coupling "Coupling is typically contrasted with Cohesion. Cohesion is measurement of how closely related the functions are WITHIN a Module. Coupling is a measurement of the level of dependency BETWEEN several Modules"




Blank




The Balance Between Cohesion & Coupling "High cohesion and Low Coupling usually indicates a well-structured design. High Cohesion is desirable Modules written with high cohesion tend to be more understandable




more reliable




Coupling is Achieved Via "The use of Global Variables Parameters Return values We shall explore each Concepts Subsequently"




Blank




Lecture Progress "Introduction to Programming structures 1: Modules Cohesion and Coupling Local and Global variables Parameters Return values"




Blank




Local Variables "Local variables may be used only by a module itself. Other modules have no knowledge of these variables. This allows cohesion to take place. In a case of multiple programmers involved in a project




The use of local variables is not affected by the concern of variable name duplication.
To use the values of a local variable in a module by other modules is achieved using:
PARAMETERS or RETURN VALUES."




Global Variables "All modules have knowledge of global variables and Global variables can be seen and used by all modules. The use of global variables defeats one of the purposes of cohesion




in
In that it allow for the duplication of variable names in different modules.
Global variables allow Data Coupling through the entire program
Only those variables that will be used in all modules should be designated as GLOBAL VARIABLES. "




Lecture Progress "Introduction to Programming structures 1: Modules Cohesion and Coupling Local and Global variables Parameters Return values"




Blank




Parameters "Parameters are Local Variables that are passed from one module to another. The use of parameters allow programmers to work independently in groups Each section of the program is developed as a Cohesive Module




coupled together using Parameters
They are placed after the module name and within parentheses




Terminologies related to Parameters "The Calling module vs the Called module




The Formal vs Actual parameter listings




Calling Module & Called Module "Calling Module ControlPay"




Blank




Formal vs Actual Parameters "Formal Parameters are list of parameters that follow the module name at the beginning of the Called Modules. Actual Parameters are list of parameters that follow the module name being excuted in the Calling Module."




Blank




Important Notes on Parameters "Variable names for Actual and Formal parameters may not be the same




and they may refer to the same value.
The values are sent and received according to the position in the way they are listed:
i.e. First formal parameter corresponds to first actual parameter"




Lecture Progress "Introduction to Programming structures 1: Modules Cohesion and Coupling Local and Global variables Parameters Return values"




Blank




Return Values "A Return Value is the result of a function. Recall: When Functions are used within another instruction




they have a Return Value.
E.g. What do we expect from function SUM (5




Return Value in Modules "In the case of the inter-module communication




the Return Value is only sent out of the Called Module into the Calling Module.
In a coupling diagram
The arrowhead would be a single-headed arrow




Study the Data Dictionary Below ""




Blank




In-class Exercise: Given the Following "ComputeBill Bill=Converter (ExchangeRate




CostPerItem)*ItemQuantity //Computes bill
PrintInNaira(Bill)
Converter (Rate




Called and Calling Modules "Calling Module ComputeBill Bill= Converter (ExchangeRate




CostPerItem) * ItemQuantity
PrintInNaira (Bill)
Called Modules
Converter (Rate




Formal &Actual Parameters; Local Variables "Formal Parameters Rate Price toPrint Actual Parameters ExchangeRate CostPerItem Bill"




Blank




Assignment "Document your Understanding of the differences between: Call-by-Value Parameters Call-by-Reference Parameters Submission is via Moodle Lifeline is"




Blank




Assignment Two "Read Chapter Four of the Text Book-Problem Solving Programming Concepts Explain each Concept discussed using an Example You Created Yourself E.g. Explain Modules




coupling




Blank




Blank