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
0
votes
1 answer
Maintain Object State Information when Calling Overloaded Constructor from Default Constructor
That question title is a mouthful.
Basically, I am creating a hash table structure that uses doubly linked lists within a vector. Everything works fine when I create the object using my overloaded constructor, but using the default constructor…

randomusername
- 107
- 2
- 10
0
votes
1 answer
Model form with JavaScript in EF
How made JavaScript cohesion work? Lets me explain better: I have my index page that call models forms with jquery dialogs, but I don't want put all javascript in index page, instead I want the jquery separate for page.
Model form
This work
…

Eduardoxvii
- 99
- 1
- 8
0
votes
1 answer
Applying Law of Demeter in a way that does not improve design
Suppose, we have the following Boy class that tries to arrange a date with a Girl by analyzing her schedule (example in Java):
public class Boy {
public boolean tryArrangeDate(Girl girl, Date time) {
boolean success = true;
for…

Volodymyr Tsukur
- 275
- 1
- 3
- 10
0
votes
2 answers
Share important instances without coupling
Let's say you're writing a "bigger" application and you want to log certain errors in your classes. Now almost every class needs access to a Logger.
One simple solution would be the following (PHP, but that doesn't matter):
class SomeClass {
…

MarcDefiant
- 6,649
- 6
- 29
- 49
0
votes
3 answers
Is this a violation of the single responsiblity principle?
I have the following method and interface:
public object ProcessRules(List rules)
{
foreach(IRule rule in rules)
{
if(EvaluateExpression(rule.Exp) == true) return rule.Result;
}
//Some error handling here for not…

LJM
- 6,284
- 7
- 28
- 30
0
votes
2 answers
Difference between code tangling and cohesion?
In relation with crosscutting concerns and aspect oriented programming, you often read about code tangling. This article 1 desciribes code tangling as:
Modules in a software system may simultaneously interact with several requirements. For example,…

Iri Iri
- 15
- 3
0
votes
1 answer
How does High Cohesion help us reduce Coupling?
Assume methods M1 and M2 have strongly related responsibilities
First example:
If
• M1 and M2 are defined within class A ( thus class A is highly cohesive )
• class B uses A.M1 and class C uses A.M2
then
• A is coupled with both B and C classes
•…

user1483278
- 929
- 1
- 9
- 17
-1
votes
1 answer
Increased cohesion in simple java program
I have a small java program that collects 10 words written by a user and prints them in specified orders. As it stands, the program works, but it is not cohesive.
My issue stems from not knowing enough about the concept of cohesion to work on…

Kyrre
- 670
- 1
- 5
- 19