Cohesion and coupling in software engineering ppt
#Cohesion and coupling in software engineering ppt how to#
Have to look at many components to determine the current state of a variable Side-effects require looking at all of the code in a function to see if there are any global effects Changes in one component to the declaration requires changes in all other components Identical list of global variables must be declared for component to be reused Component is exposed to more data than is neededġ2 Control Coupling A component passes control parameters to coupled components May be good or bad depending upon the situation Bad when the component must be aware of internal structure and logic of another component Good if parameters allow factoring and reuse of functionalityĪcceptable A sort function that accepts a comparison function as an argument Component p calls component q and q returns a flag indicating an error (if any) occurred Unacceptable Component p calls component q and q returns a string indicating the error (if any) that occurredġ4 Stamp Coupling A component passes a data structure to another component that does not have access to the entire structure Requires a second component to know how to manipulate the data structure (e.g., needs to know about the implementation) May be necessary due to efficiency factors: this is a choice made by insightful designers, not lazy programmerĪddress verification Address verification accepts a Customer data structure as an argument, “parses it” and verifies the address bool VerifyAddress (Customer customer) ġ6 Data Coupling Two components are data coupled if there are homogeneous data items Every argument is a simple argument or data structure in which all elements are used Good, if it can be achieved Easy to write contracts for this and modify component independentlyġ7 Cohesion The degree to which all elements of a component are directed towards a single task and all elements directed towards that task are contained in a single component Internal glue with which component is constructed All elements of a component are directed toward and essential for performing the same task High is goodġ8 The range of Cohesion Functional High Cohesion Informational global coupling)Īll components have read/write access to a global data block Components exchange data using the global data block (instead of arguments) A single component with write access where all other components have read access is not Common Coupling High Coupling Content Coupling Common Coupling Control Coupling Stamp Coupling Loose Coupling Data Coupling Uncoupled Low Couplingĩ Content Coupling A component directly references (shares) the content of another module Component p modifies a statement of component q Component p refers to local data of component q Content coupled components are inextricably interlinked Changes to component p requires a change to component q (including recompilation) Reusing component p requires using component q alsoġ0 Common Coupling Using global variable (i.e.
No dependencies Component A Component B Component C Component D
Maximize internal interaction (Cohesion) Easier to understand Easier to test Minimize external interaction (Coupling) Can be used independently Easier to replaceĬomponent independence High Cohesion Low CouplingĤ What is Coupling? Coupling is a measure of the independence of components Coupling is related to Cohesion It is an indication of the strength of the inter-connections between the components in a designĥ Highly Coupled These types of systems have multiple inter-connections with components dependent upon each other Component A Component B Component C Component DĦ Loosely Coupled Loosely coupled systems are made up of components which are independent or almost independent Component A Component B Component C Component Dħ Uncoupled Uncoupled components have NO interconnections Presentation on theme: "Coupling and Cohesion 1."- Presentation transcript: