Difficulty: Easy
Correct Answer: Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose.
Explanation:
Introduction / Context:
Cohesion and coupling are two important design qualities in object oriented software engineering. Cohesion describes how closely related the responsibilities of a single module or class are, while coupling describes how strongly different modules depend on each other. This question asks you to identify the most accurate statement about cohesion in the context of class design.
Given Data / Assumptions:
• We are working in an object oriented context, such as Java, C# or C++.
• The focus is specifically on cohesion, not on coupling.
• The options mention hiding implementation details, knowledge of other classes and single, well-focused purpose.
• We assume standard textbook definitions used in software engineering courses.
Concept / Approach:
Cohesion refers to how strongly the responsibilities of a single class or module belong together. High cohesion means a class has a clear, focused purpose and all its methods and data are directly related to that purpose. Low cohesion means the class tries to do many unrelated things, making it harder to understand, test and maintain. While encapsulation and low coupling are related concepts, only one option correctly captures the essence of cohesion as single responsibility and focus.
Step-by-Step Solution:
Step 1: Recall that high cohesion is often summarized as "do one thing and do it well" for each class or module.
Step 2: Compare this idea with the option that states a class should have a single, well-focused purpose.
Step 3: Recognize that hiding implementation details is mainly about encapsulation, not cohesion, even though they are related good practices.
Step 4: Recognize that limiting how classes know about other classes through their APIs relates more directly to coupling.
Step 5: Choose the option that directly states the single, well-focused purpose principle, which is the core of cohesion.
Verification / Alternative check:
The Single Responsibility Principle (SRP), one of the SOLID principles, states that a class should have only one reason to change. This is a practical expression of high cohesion: all its responsibilities are tightly related. Standard software engineering texts describe cohesion as the degree to which the elements of a module belong together, emphasizing a narrow, consistent role. This aligns perfectly with the idea of a single, well-focused purpose for each class.
Why Other Options Are Wrong:
Option A describes encapsulation, which is about hiding implementation details behind a well-defined interface so internal changes do not affect users. Option B describes low coupling, where classes interact with others only through clear, stable APIs and avoid unnecessary dependencies. Both are important OO principles, but they are not the definition of cohesion. Option D ("None") is wrong because option C accurately captures the notion of cohesion.
Common Pitfalls:
A common pitfall is to mix up cohesion and coupling because they are often discussed together. Remember that cohesion is internal to a class or module (how well its parts fit together), while coupling is about relationships between different classes or modules (how tightly they depend on each other). Another mistake is to think high cohesion means fewer methods; in reality, it means that all methods are related to the same core responsibility, regardless of their number.
Final Answer:
Cohesion is best described as ensuring that a class is designed with a single, well-focused purpose, which matches option C.
Discussion & Comments