1 / 6

Coupling Cohesion

Coupling Cohesion. Chandan R. Rupakheti Steve Chenoweth (Chapter 18). Outline. Coupling and Cohesion Command and Query Separation Principle. Types of Coupling. Tight to loose coupling Content : Module A has access to local data of Module B

bayle
Download Presentation

Coupling 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 Cohesion Chandan R. Rupakheti Steve Chenoweth (Chapter 18)

  2. Outline • Coupling and Cohesion • Command and Query Separation Principle

  3. Types of Coupling • Tight to loose coupling • Content: Module A has access to local data of Module B • Common: Global variable shared between two modules • External: Share an externally imposed data format or communication protocol • Control: Module A controls the control flow of module B through flags • Stamp: Modules share a composite data structure but uses only a part of it • Data: Modules share data through parameters • Message: Modules communicate via message passing (e.g. Observer) • No Coupling: Modules do not communicate at all

  4. Types of Cohesion • Worst to best cohesion • Coincidental: When parts of a module is grouped arbitrarily, e.g. Utilities class • Logical: Grouped because they are logically categorized to do the same thing, e.g. MouseListener • Temporal: Grouped at runtime, e.g. exception processing function that does multiple task, e.g. close file, log error, and notify users • Procedural: Grouped because they follow a certain sequence of execution, e.g. function which checks file permission and opens it • Communicational: Grouped because they operate on the same data • Sequential: Grouped because the output from one part is the input to another part • Functional: Grouped because they all contribute to a single well-defined task of the module

  5. Command-Query Separation Principle • Each method should be either a command or a query • Command Method • Performs an action, typically with side effects, but has no return value • Query Method • Returns data but has no side effects • Why is this principle important? • Principle of least surprise, side effects only happen in “void” methods • Provides for most flexible interface, e.g. a value can be queried multiple times without changing it

  6. Things to Do Next • Look at the quiz for today, and the zipped program. • Answer the related questions about coupling! • Answer the last question about cohesion! • Turn in after class, as usual, but please also be ready to discuss your answers in class!

More Related