CPSC 3720 - DAY 12 FEBRUARY 13, 2017 ================================================================================ COUPLING -------- .One component modifies another. .Example: .Component directly modifies another's data .Component modifies another's code, e.g., jumps (goto) into the middle of a routine .Example: .Program looks up customer info .Can't find it .Adds customer directly to the data structure. Common Coupling .More than one component share data such as global data structures. .Usually a poor design choice because: .Lack of clear responsibility for the data .Reduces readability .Difficult to determine all the components that affect a data element (reduces maintainability) .Difficult to reuse components .Reduces ability to control data access. External Coupling Two components share something externally imposed External file Device interface Protocol Data format Control Coupling Component passes control parameters to coupled components. ex. flags in UNIX May be either good or bad, depending on situation Bad if the parameter indicates completely different behavior Good if parameters allow factoring and reuse of functionality Good example: sort that takes a comparison function as an argument. The sort function is clearly defined: return a list in sorted order, where sorted is determined by a parameter. Stamp Coupling Component passes a data structure to another component that does not have access to the entire structure. Requires second component to know how to manipulate the data structure (e.g. needs to know about implementation) The second has access to more information than it needs. May be necessary due to efficiency factors. Example: Customer Billing System The print routine of the customer billing system accepts customer data structure as an argument, parses it, and prints the name, address, and billing information. Uncoupled Completely uncoupled components are not systems. Systems are made of interacting components Cohesion A number of dependencies within the system. A subsystem contains many related objects and task Cohesion is high A subsystem contains many unrelated objects Cohesion is low We want HIGH cohesion Often contradicts with low coupling.