1 / 30

Chapter 10

Chapter 10. Communication between modules, cohesion and coupling. Objectives. To introduce communication between modules To develop solution algorithms that pass parameters between modules To introduce cohesion as a measure of the internal strength of a module

sharla
Download Presentation

Chapter 10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 10 Communication between modules, cohesion and coupling

  2. Objectives • To introduce communication between modules • To develop solution algorithms that pass parameters between modules • To introduce cohesion as a measure of the internal strength of a module • To introduce coupling as a measure of the extent of information interchange between modules

  3. 10.1 Communication between modules

  4. Communication between modules • Necessary to consider flow of information between modules • This flow of information is called ‘intermodule communication’ and can be accomplished by the scope of the variable

  5. Communication between modules • Scope of a variable • The portion of a program in which that variable has been defined and to which it can be referenced • Variables can be global where the scope of the variable is the whole program • Scope of the variable is simple the module which it is defined

  6. Communication between modules • Global data • Date that can be used by all the modules in a program • Every module in the program can access and change data • Lifetime of a global variable spans the execution of the whole program

  7. Communication between modules • Local data • Variable are defined within the submodule are called local variables • The scope of a local variable is simply the module in which it is defined • The lifetime of a local variable is limited to the execution of the single submodule in which it is defined

  8. Communication between modules • Side effects • Side effect is a form of a cross-communication of a module with other parts of a program, • Occurs when a subordinate module alters the value of a global variable inside a module

  9. Communication between modules • Passing parameters • Parameters are simply data items transferred from a calling module to its subordinate module at the time of calling • To pass parameters between modules, two things can happen: • The calling module must name the parameters that it wants to pass to the submodule • The submodule must be able to receive those parameters and return them to the calling module if required

  10. Communication between modules • Formal and actual parameters • Parameters names that appear when a submodule is defined are known as formal parameters • Variables and expressions that are passed to a submodule in a particular call are called actual parameters

  11. Communication between modules • Value and reference parameters • Parameters may have one of three function: • To pass information from a calling module to a subordinate module • To pass information from a subordinate module to its calling module • To fulfil a two-way communication role

  12. Communication between modules • Value and reference parameters • Value parameters • Value parameters pass a copy of the value of a parameter from one module to another • Reference parameters • Reference parameter pass the memory address of a parameter from one module to another

  13. Communication between modules • Hierarchy charts and parameters • Data parameters contain actual variables or data items that will be passed between modules • Status parameters act as a program flag and should contain just one of two values; true or false Data parameters Status parameters

  14. 10.3 Module cohesion

  15. Module cohesion • Cohesion is a measure of the internal strength of a module • It indicates how closely the elements or the statements of a module are associated with each other • The more closely the elements of a module are associated with each other, the higher the cohesion of the module

  16. Module cohesion • Coincidental cohesion • Occurs when elements are collected into a module simply because they happen to fall together • Occur as a result of one of the following conditions: • Existing program may have been arbitrarily segmented into small modules • Existing program may have been arbitrarily subdivided to conform to a badly considered programming standard • A number of existing modules have been combined into one module

  17. Module cohesion • Logical cohesion • Logical cohesion occurs when the element of a module are grouped together according to a certain class of activity • The element falls into some general category because they all do the same kind of thing

  18. Module cohesion • Temporal cohesion • Occurs when the elements of a module are grouped together because they are related by time • Typical examples are initialisation and finalisation modules in which elements are placed together because they perform certain housekeeping functions at the beginning or end of a program

  19. Module cohesion • Procedural cohesion • Occurs when the elements of a module are related because they operate according to a particular procedure • The elements are executed in a particular sequence so that the objectives of the program are achieved

  20. Module cohesion • Communicational cohesion • Occurs when the element of a module are grouped together because they all operate on the same (central) piece of data • Are commonly found in business application because of the close relationship of a business program to the data it is processing

  21. Module cohesion • Sequential cohesion • Occurs when a module contains elements that depend on the processing of previous elements • Contain elements in which the output data from one element serves as input data to the next

  22. 10.4 Module coupling

  23. Module coupling • Coupling is a measure of the extent of information interchange between modules • Tight coupling implies large dependence on the structure of one module by another • Loose coupling is the opposite of tight coupling. Modules with loose coupling are more independent and easier to maintain

  24. Global data structure Module A Module B Module coupling • Common coupling • Occurs when modules reference the same global data structure • External coupling • Occurs when two or more modules access the same global data variable (similar to common coupling except that the global data is an elementary data item, rather than a data structure) Global data variable Module A Module B

  25. Module A Module B Module coupling • Control coupling • Occurs when a module passes another module a control variable that is intended to control the other module’s logic • Stamp coupling • Occurs when one module passes a non-global data structure to another module in the form of a parameter Module A Data structure Module B

  26. Module coupling • Data coupling • Occurs when a module passes a non-global data variable to another module (similar to stamp coupling except that the non-global data variable is an elementary data item, nota data structure) Module A Elementary data item Module B

  27. Module coupling • Summary of coupling levels • If the programming language allows it, try to uncouple each module from its surroundings by • Passing data to a subordinate module in the form of parameters, rather than using global data • Writing each subordinate module as a self-contained unit

  28. Summary • Introduced communication between modules and parameters. • Intermodule communication is the flow of information or data between modules. • Passing of parameters was introduced as a form of intermodule communication.

  29. Summary • The differences between formal and actual parameters and value and reference parameters was explained. • Module cohesion and module coupling must be considered when designing modular programs. • Cohesion is a measure of the internal strength of a module. • Seven levels of cohesion were discussed.

  30. Summary • Coupling is a measure of the extent of information interchange between modules. • Five levels of coupling were discussed.

More Related