Understanding Coupling and Cohesion Principles in Software Design

coupling cohesion n.w
1 / 6
Embed
Share

Learn about different types of coupling and cohesion in software design, as well as the Command-Query Separation Principle. Explore how these concepts impact the structure and efficiency of software systems.

  • Software Design
  • Coupling
  • Cohesion
  • Command-Query
  • Principles

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

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 2

  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 3

  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 4

  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 5

  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! 6

More Related Content