1 / 28

Cohesion and Coupling

Cohesion and Coupling. 01/01/10. Coupling. The amount of interaction among components in a system. Indications of Coupling. Coupling Types. Content coupling Common coupling External coupling Control coupling Stamp coupling Data coupling Uncoupled. Content and Common Coupling.

ciqala
Download Presentation

Cohesion and Coupling

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. Cohesion and Coupling 01/01/10

  2. Coupling • The amount of interaction among components in a system

  3. Indications of Coupling

  4. Coupling Types Content coupling Common coupling External coupling Control coupling Stamp coupling Data coupling Uncoupled

  5. Content and Common Coupling • The components share data via direct access to data stores: • One component depends on the internal workings of another: • Usually a poor design choice because

  6. External Coupling Two components share something externally imposed

  7. Control Coupling • Component passes control parameters to coupled components. • May be either good or bad, depending on situation. • Bad if parameters indicate completely different behavior • Good if parameters allow factoring and reuse of functionality

  8. Stamp Coupling • Component A passes a data structure to component B • B only uses part of the data • Requires B to know how to manipulate the data structure (eg needs to know about implementation) • B has access to more information that it needs

  9. Data Coupling • Component A passes data to component B • Not the same as Stamp Coupling: • Data (a representation), not a data structure (an implementation).

  10. The print routine takes the customer name, address, and billing information as arguments. Example Customer billing system

  11. Uncoupled Completely uncoupled components are not systems. Systems are made of interacting components.

  12. Key Idea in Object-Oriented Programming

  13. Consequences of Coupling

  14. Coupling between pairs of modules

  15. Cohesion • The degree to which all elements of a component are directed towards a single task • The degree to which all elements directed towards a task are contained in a single component • The degree to which all responsibilities of a single class are related • Note: We are talking about the contents of a single component.

  16. Types of Cohesion: low to high • Coincidental low • Logical • Temporal • Procedural • Communicational • Sequential • Functional high

  17. Coincidental Cohesion • Accidental • Worst form

  18. Logical Cohesion • Several logically related elements are in the same component. • Not related functionally, but related logically.

  19. A component reads inputs from tape, disk, and network. All the code for these functions are in the same component. Operations are related logically, but the functions are significantly different. Example

  20. Temporal Cohesion • Elements of a component are related by timing • Elements are grouped by when they are processed

  21. Procedural Cohesion • Elements of a component are related only to ensure a particular order of execution • Common to pass partial results

  22. Communicational Cohesion • Elements of a component are related by the data that they process • Component performs a series of actions related by a sequence of steps to be followed. All actions are performed on the same data.

  23. Update record in data base and send it to the printer. database.Update (record). record.Print(). Example

  24. Sequential Cohesion • The output of one component is the input to another. • Good situation • Data flows between components • (different from procedural cohesion) • Occurs naturally in functional programming languages

  25. Informational (Data) Cohesion • Module performs a number of actions, each with its own entry point, with independent code for each action, all performed on the same data. • Difference from logical cohesion

  26. Functional Cohesion • Every essential element to a computation is contained in the component. • Every element in the component is essential to the computation. • Ideal situation.

  27. Techniques for Improving Design • Increase cohesion • Design by contract • Prototype design

  28. Problem: Classify cohesion for each module • Compute average daily temperatures at various sites • Initialize sums and open files • Create new temperature record • Store temperature record • Close files and print average temperatures • Read in site, time, and temperature • Store record for specific site • Edit site, time, or temperature field

More Related