OOP · Design Principles
High Cohesion
Imagine you're developing a Student Management System.
Real-World Problem
Imagine you're developing a Student Management System. Initially, a single StudentManager class is created to handle every operation, including student registration, fee payment, attendance tracking, report generation, and email notifications.
As the application grows, new features such as online payments, SMS notifications, and advanced reporting are added. Developers continue adding methods to the same class because it already manages student-related tasks.
Over time, the class becomes very large and difficult to understand. Even a small change in one feature increases the risk of affecting unrelated functionalities, making maintenance and testing challenging.
Problem A class containing multiple unrelated responsibilities has low cohesion. Such classes become difficult to understand, modify, test, and reuse. When responsibilities are mixed together, changes in one feature often impact other parts of the class, increasing maintenance effort.
Pain Points Too many responsibilities. Difficult to maintain. Hard to test. Poor readability. Low reusability. Changes affect unrelated functionality.
Solution
The High Cohesion principle states that each class should focus on one well-defined responsibility. Instead of placing every feature inside one class, responsibilities should be divided into smaller, specialized classes. Each class should perform one specific task and collaborate with other classes when necessary.
This makes the application easier to understand, maintain, test, and extend.
Java Program 1 – Low Cohesion (Bad Design)

Java Program 2 – High Cohesion (Good Design)


Keep a class focused so its fields and methods all serve one clear purpose.
// High cohesion: every member is about temperature conversion
public class TemperatureConverter {
public double celsiusToFahrenheit(double c) {
return c * 9 / 5 + 32;
}
public double fahrenheitToCelsius(double f) {
return (f - 32) * 5 / 9;
}
public double celsiusToKelvin(double c) {
return c + 273.15;
}
}
// No unrelated logging, DB, or UI code sneaks in.