2

I encountered this phrase on this site in a discussion of code metrics in Eclipse, specifically discussing the concept of "lack of cohesion":

Cohesion is an important concept in OO programming. It indicates whether a class represents a single abstraction or multiple abstractions. The idea is that if a class represents more than one abstraction, it should be refactored into more than one class, each of which represents a single abstraction.

What is a "single abstraction" in this context?

From Difference between Encapsulation and Abstraction, I got that abstraction generally is just showing necessary details to the user (through the use of interfaces and abstract classes). And here: What is abstraction?, I got again that abstraction is to hide implementation.

How would you apply these ideas to the single abstraction term used in that article?

Community
  • 1
  • 1
committedandroider
  • 8,711
  • 14
  • 71
  • 126

1 Answers1

3

In this particular context, defined in the site you quote (cohesion), "single abstraction" means one concept. So it is strongly related to Single Responsibility Principle - a class should deal with "one thing". If a class deals with more than one thing, it will often have many different methods and variables that don't necessarily belong together, thus it would have low cohesion.

This not a common usage of this word for this purpose, from my experience it is more likely to be used in reasoning about levels/layers of abstraction, like in the other SO questions you link. They relate to a different rule, namely the Single Layer of Abstraction Principle.

BartoszKP
  • 34,786
  • 15
  • 102
  • 130