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
1
vote
1 answer
What is the most cohesive location to utilize a logger?
I've written a task manager program using Java, and made a single UI implementation for the moment in swing. The program has 3 layers at the moment. A presentation layer that interacts with the domain layer via a use case controller, and finally a…

Bnjmn
- 1,973
- 1
- 20
- 34
1
vote
3 answers
Am I right about the meaning of coupling?
I'm gonna try to write some ideas ideas about software coupling and cohesion, but I'm not sure they mean anything practical at all. So if you want to explain your answers with examples please use simple algebraic expressions imagining that algebra…

jacmkno
- 1,189
- 11
- 25
1
vote
1 answer
How to refactor these classes to interact each other?
My requirement is to use the name of the shape and draw that shape with the dimensions like in the method Draw('rectangle', 'l:10,w:20');.
There should be validation of the dimensions against the type of the shape.
These classes can be refactored…

wonderful world
- 10,969
- 20
- 97
- 194
1
vote
0 answers
What is the relationship between code coupling, cohesion and fragility?
I am trying to understand code coupling, cohesion and fragility. I wanted to check my current understanding. Currently I have come up with following conclusions:
low coupling = high cohesion = low fragility
and vice-versa:
high coupling = low…

uday
- 65
- 7
1
vote
1 answer
High Cohesion and Concurrency - Are they conflicting interests?
I was reading Robert Martin's Clean Code and in that he mentions about the code being highly cohesive:
Classes should have a small number of
instance variables. Each of the
methods of a class should manipulate
one or more of those variables.…

rkg
- 5,559
- 8
- 37
- 50
1
vote
1 answer
How Do I Avoid using Running Totals in My Code?
I am learning programing and software design and Java in school right now. The class that is getting me mixed up is Software Design. We are using Word to run simple VB code to do simple programs. My instructor says I am losing cohesion by using…

nicorellius
- 3,715
- 4
- 48
- 79
1
vote
1 answer
Is scanf cohesive or coupled?
I came to know that scanf is coupled and it is coupled because it takes different types of inputs like integer, float, char and others.
But cohesion indicates doing a single task and scanf does it(scanning input from stdin).
I agree that although it…
user3511557
1
vote
1 answer
Can routing urls in Spring framework be done easier?
Routing for a webapp in one place in one file e.g. yaml, xml or properties file to define the routing and urls for a webapp and connecting the urls with individual methods or functions seems like a good idea.Why doesn't Spring do it? The framework…

Niklas Rosencrantz
- 25,640
- 75
- 229
- 424
1
vote
1 answer
Should my class have a method for each file format, or should I delegate I/O to other, file-format-specific classes?
In a given domain, there can be multiple file formats representing similar objects or structures. For example, an object of type Track (meaning a sequence of geographical points) can be saved in .GPX, .KML, GeoJSON, WKT, ShapeFile, etc.
So, my class…

heltonbiker
- 26,657
- 28
- 137
- 252
1
vote
3 answers
Inquiry about cohesion in java programming
How would you define the following code?
a) High cohesion
b) Low cohesion
I would say High as even though takeAndGlue() does 2 things they are called with 2 separate methods, hence the stackTrace is traceable.
public class Assembler()
{
…

Rollerball
- 12,618
- 23
- 92
- 161
1
vote
2 answers
Persisting Objects while Still Preserving Loose Coupling
I working on a project in a microcontroller and I need to persist some settings. Pretend this is an iPod. I need to save various settings like CurrentSongPlaying, CurrentVolume, etc. so that when I turn on again I can restore those settings. The…

Joel B
- 12,082
- 10
- 61
- 69
0
votes
3 answers
Reusing PHP function for accessing an array item tag from XML document
I have created a website that contains that uses XML to drive some of its contents, for example, the current exchange rates as shown below.
The website compares three exchange rates and I currently use a separate functions for each city that…

newToJava
- 173
- 1
- 15
0
votes
1 answer
Increase cohesion by reusing a PHP function for multiple RSS feeds
My homepage contains weather for three cities around the world as displayed in the image
In the home page I declare 3 variables storing the RSS URL for each city
$newYorkWeatherSource =…

newToJava
- 173
- 1
- 15
0
votes
0 answers
Module Print Entity used with DOMPdf in Drupal does not apply css on the pdf
I'm using the module Entity Print in my Drupal application,my default pdf engine is DOMPdf. My nodes are built with Site Studio, when I try to print a Node, the css is not applied at all and never loaded.
Have you any recommendation ?
Reading…

Tortue
- 1
- 2
0
votes
1 answer
How to distinguish which following archetecture have lower coupling?
I have read a bounch of articles about coupling which all without exception view it from a high perspective. They rarely elaborate it with real projects.
So, there is a specific question I met:
Simplified model as following:
architecture 1
# m:…

yixuan
- 375
- 2
- 17