Skip to main content

What is Coupling? What is Cohesion? Explain different types of Cohesion and Coupling with proper example.

Understanding Coupling and Cohesion in Software Engineering

What is Coupling?

  • Coupling refers to the degree of interdependence between modules or classes in a software system.
  • High coupling indicates strong dependencies, making changes difficult and increasing the risk of unintended consequences.
  • Low coupling promotes modularity, reusability, and maintainability.

Types of Coupling

  • Content Coupling: One module directly modifies data within another. Example: Module A directly changing variables inside Module B. This is extremely undesirable.
  • Common Coupling: Modules share global data. Example: Multiple modules accessing and modifying the same global variable. Difficult to manage and understand.
  • Control Coupling: One module controls the flow of execution in another using flags or parameters. Example: Module A passing a flag to Module B to dictate its behavior. Often avoidable through better design.
  • Stamp Coupling: Modules share a composite data structure, but only use a portion of it. Example: Passing a large object when only a small subset of its data is needed. Inefficient and leads to tight coupling.
  • Data Coupling: Modules communicate through passing data parameters. Example: Module A passing specific data values to Module B. The most desirable form of coupling.

What is Cohesion?

  • Cohesion refers to how closely related the functions within a single module or class are.
  • High cohesion implies that a module performs a single, well-defined task.
  • Low cohesion suggests that a module performs unrelated tasks, making it difficult to understand, maintain, and reuse.

Types of Cohesion

  • Coincidental Cohesion: Parts of a module have no logical relationship. Example: A module containing unrelated functions such as logging and database access. Weakest form of cohesion.
  • Logical Cohesion: A module performs multiple related functions, but each is invoked independently. Example: A module performing several validation operations. Slightly improved over coincidental, but still weak.
  • Temporal Cohesion: Functions within a module are grouped because they are executed at the same time. Example: A module containing functions that are all executed during system initialization. Better than logical, but still not ideal.
  • Procedural Cohesion: Functions are grouped because they are executed in a specific order. Example: A module with functions that perform steps in a particular process. Improves upon temporal.
  • Communicational Cohesion: Functions operate on the same data. Example: A module containing functions that process data from a single input file. Strong cohesion, good design.
  • Sequential Cohesion: Output of one function serves as input for another. Example: A module with functions where the output of one is the direct input of the next. Very strong cohesion.
  • Functional Cohesion: A module performs a single, well-defined function. Example: A module calculating the area of a circle. The strongest form of cohesion and ideal.

Popular Posts

Explain Data collection methods and Techniques in UX Evaluation.

UX Evaluation: Agile Data Collection Methods & Techniques Qualitative Data Collection Methods User Interviews: Structured, semi-structured, or unstructured. Focus Groups: Moderated discussions with small groups. Contextual Inquiry: Observing users in their natural environment. Card Sorting: Organizing information architecture. Diary Studies: Users document their experiences over time. Think Aloud Protocols: Users verbalize their thoughts while using a product. Usability Testing Observations: Direct observation of user interactions. Heuristic Evaluation: Expert review against usability principles. Cognitive Walkthroughs: Step-by-step analysis of user tasks. Quantitative Data Collection Methods A/B Testing: Comparing two versions of a design. Eye Tracking: Measuring visual attention. Surveys: Gathering user feedback through questionnaires. Analytics: Tracking website or app usage data (e.g., Google Analytics). System Usability Scale (SUS): Standardized questionn...

What is Stegnography and list two examples.

Unveiling the Secrets: Understanding Steganography in Cybersecurity What is Steganography? Steganography is the art and science of hiding information within other information. It focuses on concealing the very existence of a secret message. Unlike cryptography (which scrambles messages), steganography aims to make hidden data undetectable. It's a powerful tool for covert communication and data exfiltration. Often used in conjunction with cryptography for enhanced security. Steganography Examples in Cybersecurity Hiding data within an image file: Modifying least significant bits (LSBs) of image pixels to embed secret data. The changes are usually imperceptible to the human eye. Embedding data within audio files: Similar to images, small modifications to audio waveforms can hide information without noticeably altering the sound quality.

What is LZW compression? Explain with example.

Decoding the Magic of LZW Compression: A Data Compression Deep Dive What is LZW Compression? Lempel-Ziv-Welch (LZW) is a lossless data compression algorithm. It works by replacing repeating sequences of data with shorter codes. It's widely used in GIF image format and other applications. Highly effective for data with repeating patterns. How LZW Compression Works: A Step-by-Step Guide Starts with a dictionary containing single characters. Reads the input data character by character. Concatenates characters to form strings. When a string is not found, it's added to the dictionary with a new code. The code for the longest matching string is written to the output. This process continues until the entire input is processed. LZW Compression Example: Initial Dictionary: {'A': 1, 'B': 2, 'C': 3} Input String: "ABABCABABCACC" Processing: - 'A' is encoded as 1. - 'AB' is encoded as 4 (added to diction...

Explain different compression techniques with example.

Mastering Data Compression: A Comprehensive Guide Lossless Compression Techniques Run-Length Encoding (RLE):  Represents consecutive repeating characters with a single count and character. Example: "AAABBBCC" becomes "3A3B2C". Huffman Coding: Assigns shorter codes to frequently occurring symbols and longer codes to less frequent ones. Example: In text, "e" gets a shorter code than "z". Lempel-Ziv (LZ77 & LZ78):  Identifies repeating patterns and replaces them with pointers to earlier occurrences. LZ77 uses a sliding window, LZ78 uses a dictionary. Arithmetic Coding: Represents data as a single fractional number, encoding probability. More efficient than Huffman for many cases. Lossy Compression Techniques JPEG (Joint Photographic Experts Group): Discards some image data, particularly high-frequency components, which are less noticeable to the human eye. MPEG (Moving Picture Experts Group): Uses techniques like motion compen...

what is type conversion in python? Explain with the suitable example.

Data Compression: Mastering Type Conversion in Python What is Type Conversion? Type conversion, also known as type casting, is the process of changing a variable's data type from one to another. Python supports both implicit (automatic) and explicit (manual) type conversion. Implicit Type Conversion Python automatically converts data types in certain situations to prevent errors. Example: Adding an integer to a float results in a float. Explicit Type Conversion We use built-in functions like `int()`, `float()`, `str()`, `bool()` etc. to explicitly change data types. Example: Converting a string "10" to an integer using `int("10")`. Example: Data Compression Context Imagine you're storing compressed file sizes (originally floats) in a database designed for integers. Explicit type conversion (using `int()`) would truncate the decimal part, losing precision but saving space. This is a type of lossy compression. Converting from a larger data t...