High cohesion is when you have a class that does a well defined job. Low cohesion is when a class does a lot of jobs that don't have much in common.
Questions tagged [cohesion]
83 questions
2
votes
1 answer
Is a class with only one function cohesive enough?
In his post SOLID: the next step is Functional, Mark Seemann states:
If you keep driving your design towards smaller and smaller interfaces, you'll eventually arrive at the ultimate Role Interface: an interface with a single method [...] If you…

user6110002
- 53
- 2
2
votes
4 answers
Coupling and cohesion example (Refactoring the code)
I know what coupling and cohesion mean.
I have got the following example and it has some maintainability issues and therefore it needs some refactoring:
The problem is, I could not relate any coupling, cohesion or any other maintainability issue…

Dee
- 483
- 2
- 11
- 24
2
votes
4 answers
What are techniques for increasing cohesion while maintaining loose coupling?
Loose coupling, high cohesion for a
maintainable application
This is the battle-cry that I hear over and over. There is plenty of advice on how to loosely couple components.
Base on interfaces and inject all dependencies
Use events
Use a…

George Mauer
- 117,483
- 131
- 382
- 612
2
votes
1 answer
Open Source or Freeware C Code Metrics tools?
I have been trying to find a tool (hopefully for MAC OS X but I don't mind migrating) -- that works -- for those dimensions but I had no luck. Maultech mention some, and so does this page but I was unable to make them work. Metre and ccount (listed…

Oeufcoque Penteano
- 593
- 5
- 25
2
votes
5 answers
Tool to identify cohesive blocks of (JAVA) code
I am wondering if there is a tool that can identify cohesive blocks of code within JAVA source code.
For example if I had a long method that I would like to extract another method from - is there any tool that automatically can tell me large chunks…

KoenigGunther
- 130
- 1
- 8
2
votes
1 answer
Where to put ajax scripts for forms (what controller) in mvc?
This is my situation:
I have a single view (lets call it view V) with a formform with multiple combo box for selecting some parameters.
I want to load the options of those combo box via AJAX calls dynamically (selecting one item on a combobox will…

JavierIEH
- 743
- 8
- 19
1
vote
2 answers
Do I need to make Custom Events in this situation?
For hobby I'm making a game. The game has a monster chasing the human (Pacman-like). When the Pacman is stuck, can eat the human or does some move; an event should be raised. This is because my program became not-oop because all the objects had to…

guidsdo
- 432
- 2
- 9
1
vote
1 answer
Cohesion principle in a class diagram (online shop)
I would like to know which of the following 2 versions is the "more correct" according to the cohesion principle.
Version #1: my main thought was answering the question (what can/does a customer do?)
Version #2: here I was thinking that methods…

Ninorin
- 35
- 5
1
vote
2 answers
Using Enum to store constants and use those constants in multiple classes
I'm currently writing a genetic algorithm solving the traveling salesman problem. There are some "constants" I use at multiple places. Those values, however, need to be precalculated, thus, I can't store them into a private static final…

John The Fisherman
- 13
- 3
1
vote
1 answer
Bonding/Merging of Bodies after collision in Abaqus
Is it possible to model the merging or bonding of bodies or mesh elements after a collision in Abaqus? From what I have seen so far, cohesive elements and cohesive contact can be used to model the adhesives between two components or interfacial…

jgk5141
- 11
- 2
1
vote
1 answer
Does the DAO pattern spoils cohesion /SRP?
Let's use as example:
class AccountDAO {
create(){..}
read(){..}
update(){..}
delete() {..}
}
How many responsibilities are there? 1 or 4?

ejaenv
- 2,117
- 1
- 23
- 28
1
vote
1 answer
Why are maximally cohesive classes not advisable or possible to create?
I'm learning the book of Robert C. Martin "Clean Code" (2009) and I've stumbled upon the concept of cohesion (Chapter 10).
Robert quotes:
A class in which each variable is used by each method is maximally
cohesive. In general it is neither…

K. Elghali
- 35
- 1
- 5
1
vote
3 answers
Method Cohesion
I have persistent objects that are saved to the DB (insert, update, delete). Is it better to combine this logic in a single method - Save or have 3 separate methods for cohesion?

mwok
- 257
- 1
- 4
- 7
1
vote
2 answers
Low cohesion in helper/storage classes, is that really wrong?
Having a class such as this, with two getters for two instance variables:
class A
{
_fieldA;
_fieldB;
GetA()
GetB()
GetSpecialNumber(int a)
{
//calculation not requiring any fields
}
}
The class will be classified as lacking…

John V
- 4,855
- 15
- 39
- 63
1
vote
4 answers
Coupling/Cohesion
Whilst there are many good examples on this forum that contain examples of coupling and cohesion, I am struggling to apply it to my code fully. I can identify parts in my code that may need changing. Would any Java experts be able to take a look at…

user559142
- 12,279
- 49
- 116
- 179