1 / 23

Coupling and Cohesion

Coupling and Cohesion. Rajni Bhalla. Introduction. This presentation demonstrates the Concept of Coupling and cohesion. This presentation will cover up the basic part of coupling and cohesion (i.e.) Module

ricardol
Download Presentation

Coupling and Cohesion

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. Coupling and Cohesion RajniBhalla

  2. Introduction This presentation demonstrates the Concept of Coupling and cohesion. This presentation will cover up the basic part of coupling and cohesion (i.e.) Module Will also cover the practical aspects of how both these concepts are being implemented.

  3. Base of Coupling and Cohesion - Module • Module is basically a part some software which basically contains a abstracted components of base software. • We can also call the module as the sub-system of the complete software. • The immediate parts of the sub-system can be classes, functions, packages or compilation units etc.

  4. Why modularity • Easier to understand and explain • Easier to document • Programming an individual module is easier • Testing and debugging is easier • Bug tracking and fixing is easier & faster • reusable

  5. Coupling • Coupling indicates: • how closely two modules interact or how interdependent they are. • The degree of coupling between two modules depends on their interface complexity.

  6. Coupling • The extent to which modules are interdependent is called as coupling also referred as inter-module coupling. • It is measured in the degree of independence between module(low to high). • Loosely coupled: Little interaction between two modules. • Tightly coupled: High degree of interaction between modules.

  7. Categories of Coupling • No Direct Coupling • Data coupling • Stamp coupling • Control coupling • Common coupling • Content coupling

  8. No Direct Coupling • This coupling contains independent modules. • Do not act as sub system. • Example • Class for adding two variables • Class for subtracting two variables etc.

  9. Data Coupling • In this One module passes non-global variables to another module • Module are independent of each other • Can only be communicated through passing data elements or information • Two modules has no need to know what goes on inside each other module. • Higher level module needs only to know what data to pass its subordinates. • Subordinate module only need to know what data it requires and what data is return.if they communicate via a parameter: • an elementary data item, • e.g an integer, a float, a character, etc.

  10. Stamp Coupling • In this one module passes non-global data structure to another module. • Modules are more dependent on each other. • A change in data structure will affect all modules that use it. • The two module must have some knowledge of the internal workings of other modules that use the same data structureTwo Modules are stamp coupled if they communicate via a composite dataitem • such as a record in PASCAL • or a structure in C.

  11. Control Coupling • In this module passes control flags or switch modules to another module • The Sending module must know a detail about the inner workings of the receiving module. • Code convention is used :- Flag’s label must start with a verb.

  12. Common Coupling • This occurs when modules refer to the same global data area or data structure. • Modules that use the same area having quite high level of interdependence • This is undesirable as the error can spread throughout the system.Two modules are common coupled, • if they share some global data.

  13. Content Coupling • This occur when one module refers to the inner workings of another module. • Modules are highly inter dependent. • One module can alter data in other module or change a statement coded in other module. • Content coupling exists between two modules: • if they share code,

  14. Cohesion • This is the measure of strength of the association of elements with in a module. • Cohesion is highest in modules that have a single, clear, logically independent responsibility.

  15. Categories of Cohesion • Functional Cohesion • Sequential Cohesion • Communicational Cohesion • Procedural Cohesion • Temporal Cohesion • Logical Cohesion • Coincidental Cohesion

  16. Functional Cohesion • The name of module will indicate its function • All statements within a module are based on one function. • It is the best cohesion as the module performs single specific function. • Different elements of a module cooperate: • to achieve a single function, e.g. managing an employee's pay-roll.

  17. Sequential Cohesion • The instructions inside a modules are related to each other through the input data. • The first instruction acts on the data that are passed into the module, the second instruction use the output of the first instruction as its input and so on • Sequence of events is very important. • Eg • output from one element of the sequence is input to the next. sort search display

  18. Communicational Cohesion • The activities are related to each other by the data that the modules used • Each instruction acts on the same input data or is concerned with the same output data • Sequence is not important • Example: • the set of functions defined on an array or a stack.

  19. Procedural Cohesion • Instructions are related to each other through flow of control • Instructions are grouped together because of a particular procedural order. • The instruction are more related to other modules than they are to each other. • certain sequence of steps have to be carried out in a certain order for achieving an objective, • e.g. the algorithm for decoding a message.

  20. Temporal Cohesion • Instructions in a module are related to each other through the flow of control • Instruction are group together because they occur at about the same point of time • The module contains tasks that are related by the fact: • all the tasks must be executed in the same time span. • Example: • The set of functions responsible for • initialization, • start-up, shut-down of some process, etc.

  21. Coincidental cohesion • The module performs a set of tasks: • which relate to each other very loosely, if at all. • the module contains a random collection of functions. • functions have been put in the module out of pure coincidence without any thought or design.

  22. Logical cohesion • All elements of the module perform similar operations: • e.g. error handling, data input, data output, etc. • An example of logical cohesion: • a set of print functions to generate an output report arranged into a single module.

  23. Determining Cohesiveness • Write down a sentence to describe the function of the module • If the sentence is compound, • it has a sequential or communicational cohesion. • If it has words like “first”, “next”, “after”, “then”, etc. • it has sequential or temporal cohesion. • If it has words like initialize, • it probably has temporal cohesion.

More Related