Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.
Fun, engaging games to boost memory, math fluency, typing speed, and English skillsβperfect for learners of all ages.
Listen to a student-teacher conversation explaining the topic in a relatable way.
Signup and Enroll to the course for listening the Audio Lesson
Cohesion measures how closely related and focused the responsibilities of a single module are. It reflects the 'single purpose' of a module, which is crucial for maintainability and understandability.
So, is high cohesion good for a module?
Exactly! High cohesion indicates that all parts of the module work together for a single purpose. This makes it easier to maintain.
What happens with low cohesion?
Low cohesion can lead to confusion, making a module harder to understand and maintain. It's like a cluttered workspace!
So how many types of cohesion are there?
Great question! There are seven categories of cohesion we need to explore, starting from functional cohesion to coincidental cohesion. Let's dive into the definitions next.
Signup and Enroll to the course for listening the Audio Lesson
Functional cohesion is the ideal type. It means all elements of a module contribute to a single, well-defined function.
Can you give me an example?
Sure! Think of a module named `CalculateSquareRoot()`. Everything in that module is focused on calculating the square root.
What makes it so desirable?
Modules with functional cohesion are easier to understand, test, and reuse. They minimize side effects from changes, making maintenance straightforward.
Sounds like the perfect module!
It is! Let's discuss sequential cohesion next.
Signup and Enroll to the course for listening the Audio Lesson
Now, letβs categorize the rest of the types. Starting with sequential cohesion, which has output from one operation serving as input to another.
Could you provide a real-world analogy for this?
Think of streaming a movie: you must buffer first before watching. Similarly, in a `ProcessOrder()` module, each step relies on the previous step's output.
Whatβs next after that?
Next is communicational cohesion, where different operations share data but aren't necessarily dependent on each other. For example, a `CustomerOperations()` module can update, retrieve, and delete customer records using the same customer data.
I see! So each type builds on clarity and purpose?
That's right! Clarity and independence in modules promote better software design.
Signup and Enroll to the course for listening the Audio Lesson
Now we get to low cohesion types, starting with procedural cohesion.
Is this why functionally different processes are grouped together?
Exactly! While the procedures are ordered, they may lack functional relevance, such as in `PerformStartup()`.
What about temporal and logical cohesion?
Temporal cohesion groups actions happening at the same time without real function overlap. In contrast, logical cohesion uses a parameter to determine which action to take, like a `ProcessFile(fileType)` method.
And the worst type?
That would be coincidental cohesion. Random groupings, leading to modules that do not cooperate or communicate effectively.
That sounds like a nightmare to manage!
Certainly! Cohesion quality directly affects maintainability. The goal should always be high cohesion.
Signup and Enroll to the course for listening the Audio Lesson
How do we achieve high cohesion? First, by combining closely related responsibilities into focused modules.
And what else?
Avoid grouping irrelevant operations. For example, keep initialization tasks separate and structured.
So logical and coincidental types should be avoided?
Yes! Focusing on functional, sequential, or communicational types keeps our modules strong and manageable.
Will high cohesion impact coupling too?
Definitely! There's a strong relationship between high cohesion and low coupling, promoting better system design overall.
Read a summary of the section's main ideas. Choose from Basic, Medium, or Detailed.
The section discusses the significance of cohesion in software design by classifying it into various types ranging from functional cohesion, which represents an ideal case, to coincidental cohesion, which is detrimental. Each type is explained in terms of its definition, characteristics, and specific examples.
Cohesion is a critical concept in software design, reflecting the degree to which the elements of a module belong together. This section categorizes cohesion from the ideal to the undesirable forms, detailing their definitions, characteristics, and implications for software design.
Definition: All elements contribute to a single well-defined function.
Characteristics: Functionality can be expressed in one concise statement; example modules include CalculateSquareRoot()
and ValidateCreditCardNumber()
.
Emphasis: Most desirable type of cohesion.
Definition: Output from one part serves as input to the next, creating a sequence of operations relevant to a single purpose.
Characteristic Example: ProcessOrder()
involves validating data, calculating cost, and generating an invoice.
Definition: Elements operate on the same data, performing distinct functions.
Example: A module CustomerOperations()
retrieves, updates, and deletes customer records, all using common customer data.
Definition: Elements grouped by the sequence of execution rather than function.
Example: PerformStartup()
executes database initialization followed by user authentication without direct relation.
Definition: Elements executed at the same time but unrelated in functionality.
Example: StartupTasks()
might open log files and initialize variables, executed together but unrelated actions.
Definition: Elements perform similar but distinct actions grouped by a parameter.
Example: ProcessFile(fileType)
acts based on the file type but lacks a cohesive function.
Definition: Elements grouped randomly without meaningful relationships.
Example: MiscellaneousFunctions()
containing various unrelated functions.
Cohesion plays a pivotal role in module design, where striving for high cohesion and avoiding low cohesion is fundamental in building maintenance-friendly software.
Dive deep into the subject with an immersive audiobook experience.
Signup and Enroll to the course for listening the Audio Book
Functional cohesion refers to a situation where all components of a software module are highly related and perform a specific function. In this case, a module is dedicated to a single task - for example, calculating the square root of a number. Each part of this module contributes directly to this specific task, making the module highly focused and effective. The output of the module can be easily articulated, and every component is essential to perform its job, which provides clarity and reduces maintenance challenges.
Imagine a well-organized library, where each section is dedicated to a specific genre of books. Just like a module with functional cohesion focuses on one task, this library section only deals with science fiction books, making it easy for visitors to find what they need quickly.
Signup and Enroll to the course for listening the Audio Book
In sequential cohesion, components of a module interact sequentially. This means that each function or component's output is directly required by the next component. For instance, in a module that processes an online order, the flow would be: first validating the data, then calculating costs, and finally generating an invoice. This type of cohesion reinforces efficiency as each step logically follows from the previous one, improving the module's clarity and reducing potential errors.
Think of baking a cake where you follow a specific sequence of steps: first mix the ingredients, then pour the mixture into a pan, and finally bake it in the oven. Each step relies on the successful completion of the previous one, just as sequential cohesion relies on the output of one function being needed for the next.
Signup and Enroll to the course for listening the Audio Book
Communicational cohesion occurs when elements within a module work together based on shared data, even if they perform different functions. An example could be a customer operations module that handles customer details, updates addresses, and deletes records - all these actions utilize the same data structure concerning customer data. This sharing means that the module generally has better consistency and graduates towards high cohesion since alltasks are relevant to the same topic.
Consider a restaurant where a waiter takes orders, serves food, and delivers the bill. While these tasks are distinctly different, they all revolve around the same customers and dining experience, which keeps them organized and makes the waiter efficient in managing the dining process.
Signup and Enroll to the course for listening the Audio Book
This type of cohesion groups elements based on the procedure used. A procedural module may perform steps in a required order (e.g., initializing a system, loading settings, and authenticating a user). However, while the steps are ordered, they may not directly relate to one another beyond the sequence, leading to moderate cohesion. While this is better than random grouping, it lacks a tighter conceptual connection between functions, which may introduce complexities in understanding.
Think of setting up a new computer: first you connect the cables, then install the operating system, and finally set up user accounts. These steps must occur in that order for the setup to work, but they donβt interact directly with one another - each step is a standalone procedure that contributes to the overall task.
Signup and Enroll to the course for listening the Audio Book
Temporal cohesion occurs when module components are executed together because they happen around the same time, yet they serve different functions. For instance, a startup tasks module might handle opening a log file, initializing variables, and setting the system clock. Although these tasks execute in the same time frame, they do not influence each other, which dilutes the module's cohesion. Consequently, understanding and maintaining such modules can become difficult as they are not fundamentally linked.
Imagine a person preparing breakfast, where they boil the kettle, toast the bread, and fry eggs. Although all these activities happen simultaneously, they are not interdependent. You can change one task without affecting the others, which makes it harder to understand their purpose as a single coordinated effort.
Signup and Enroll to the course for listening the Audio Book
Logical cohesion arises when a module handles various functions that are similar but not closely linked. This often requires using parameters to determine which function to execute. For instance, a process file module might perform various operations based on a file type, but each of those operations operates independently. This can lead to increased complexity in the code and challenges in maintaining or modifying the module since changes to one function could require changes in handling for others.
Consider a Swiss army knife, which combines different tools (scissors, screwdriver, can opener) into one device. While all tools are logically related as they serve specific functions, using one does not relate to the operation of another. If you needed a new tool, you might have to manage incompatible features, leading to a complex setup that may not work well together.
Signup and Enroll to the course for listening the Audio Book
Coincidental cohesion means that the functions within a module are grouped arbitrarily, without any significant relation to one another. Such modules often end up cluttered with mismatched functions, making it extremely difficult to understand how they work together. Changes to one part can inadvertently affect another, leading to bugs and complicating testing and reuse efforts. This type of cohesion is considered the least desirable in software design.
Think of a junk drawer in a kitchen where you throw random items - batteries, a tape measure, scissors, and old receipts. While all items are in the same location, they are unrelated and finding something specific becomes tiring. Like this drawer, a module with coincidental cohesion lacks clarity and purpose, making it frustrating and inefficient to use.
Learn essential terms and foundational ideas that form the basis of the topic.
Key Concepts
High Cohesion: Favorable for maintainability and reusability.
Cohesion Types: Seven forms from functional to coincidental.
Design Principles: Strive for functional, sequential, or communicational cohesion.
See how the concepts apply in real-world scenarios to understand their practical implications.
A module CalculateArea()
which calculates the area of a rectangle is functionally cohesive.
A CommunicateWithAPI()
module that shares the same data set across multiple calls demonstrates communicational cohesion.
Use mnemonics, acronyms, or visual cues to help remember key information more easily.
High cohesion is key, like birds in a tree, together they thrive, functionality alive!
Imagine a chef who only prepares desserts. That's functional cohesion, as everything supports one delicious goal.
F-S-C-P-T-L-C: Funny Sequential Cats Purr Together Loningly, Coinciding β a memory tool for identifying cohesion types.
Review key concepts with flashcards.
Review the Definitions for terms.
Term: Cohesion
Definition:
A qualitative measure of how well the elements of a module work together toward a single purpose.
Term: Functional Cohesion
Definition:
Occurs when all elements in a module contribute to a single, well-defined function.
Term: Sequential Cohesion
Definition:
Refers to a situation where the output of one part of the module serves as input to another part.
Term: Communicational Cohesion
Definition:
When elements of a module operate on the same data or produce the same output data.
Term: Procedural Cohesion
Definition:
Grouping of elements in a module that follow a specific sequence of execution.
Term: Temporal Cohesion
Definition:
Grouping of elements that are executed at the same time but are not functionally related.
Term: Logical Cohesion
Definition:
Grouping of logically related but functionally distinct activities in a module.
Term: Coincidental Cohesion
Definition:
The weakest form of cohesion where elements are grouped arbitrarily without any meaningful relationship.