Questions tagged [cohesion]

26 questions
38
votes
9 answers

How to determine if a class meets the single responsibility principle?

The Single Responsibility Principle is based on the high cohesion principle. The difference between the two is that a highly cohesive classes features a set of responsibilities that are strongly related, while classes adhering to SRP have just one…
user1483278
  • 1,121
  • 1
  • 10
  • 14
12
votes
3 answers

What is logical cohesion, and why is it bad or undesirable?

From the c2wiki page on coupling & cohesion: Cohesion (interdependency within module) strength/level names : (from worse to better, high cohesion is good) Coincidental Cohesion : (Worst) Module elements are unrelated Logical Cohesion : Elements…
user39685
10
votes
6 answers

Fields vs method arguments

I just started writing some new class and it occurred to me that I was adding a lot of method arguments that are not strictly needed. This is following a habit to avoid having state in classes that is specific to some method call, rather than being…
7
votes
1 answer

Concept of functional cohesion

I made some research to better understand the concept of functional cohesion. Myers in his book "Composite structured design" has written about functional cohesion: A functional-strength module is defined as a module that performs a single specific…
flexibleHammer
  • 119
  • 1
  • 5
7
votes
3 answers

Low Coupling: Single Responsibility Principle vs Cohesion

I've read several articles on SRP and cohesion, and they seem to contradict each other as far as low coupling is concerned. Articles on cohesion argue that putting closely related responsibilities together in a class Highly_Cohesive_Class reduces…
user1483278
  • 1,121
  • 1
  • 10
  • 14
6
votes
2 answers

Does increasing the number of classes increase code complexity?

To illustrate the question, let's say we have two programmers of comparable skill that both solve the same problem. The code they turn out has roughly the same lines of code, but one programmer uses 5 classes while another programmer uses 20. Both…
5
votes
1 answer

Tight class cohesion metric, all or just public methods?

I am researching cohesion topic and found out that some claim TCC metric should only include public methods, some other sources claim all methods. Would it be wrong to use either approach? Why private methods should be excluded, as some suggest?
John V
  • 4,898
  • 10
  • 47
  • 73
4
votes
1 answer

What is the evidence that an API has exceeded its orthogonality in the context of types?

Wikipedia defines software orthogonality as: orthogonality in a programming language means that a relatively small set of primitive constructs can be combined in a relatively small number of ways to build the control and data structures of the…
hawkeye
  • 4,819
  • 3
  • 24
  • 35
4
votes
7 answers

What's the opposite of cohesive?

I was talking with my architect about some concerns with a particular approach that may result in very low level of cohesion in a set of classes. However, I couldn't think of the word that represents a low level of cohesion. I said something along…
Justin Self
  • 263
  • 2
  • 9
3
votes
2 answers

When refactoring many functions that share state in to a single class, how can you avoid writing an "escort" class?

This well-known article criticises Java on the basis that it does not allow you to write functions that do not live in a class. This flaw forces you to write classes with names that look suspiciously like verbs, such as GridCellHander or…
3
votes
3 answers

Programming by Intention, Depth-First or Breadth-First?

Say I have the following graph of dependencies between procedures/functions/methods: o / \ v e / \ / \ r f l w That is, function o first calls function v, and then function e. Function v itself first calls function r,…
2
votes
0 answers

Cohesion and coupling possible combination in software

I know what we mean by cohesion and coupling in software. And generally the best practice is to achieve high cohesion with low coupling. It seems to me though that they are inter-related. I.e. you either end up with low cohesion/high coupling or…
Jim
  • 317
  • 1
  • 3
  • 10
2
votes
2 answers

Use old legacy application code from new application

If you have a big legacy application (big ball of mud), lets call it MudApp. If you then create a new application to make us of new technology and to make a new good looking frontend because that was impossible in the MudApp. This new application is…
emajl
  • 59
  • 2
2
votes
0 answers

Packages, a controller class, and coupling vs cohesion

So I'm building my first application, in Python, and some issues have cropped up because of the lack of interfaces (I.e. explicit type declaration) My design involves several homebrew packages, and I've been taught to reduce coupling by using a…
user309290
  • 21
  • 3
2
votes
6 answers

Object Design & Cohesion - Issue & potential refactoring

Abstract I have been trying to get my head around the cohesiveness of some functionality in our code base. I’ve approached this design in different ways, and lately I’m convinced that I took the wrong approach, as in I incorrectly applied the…
1
2