Question

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, oftentimes developers simultaneously think about business logic, performance, synchronization, logging, and security. Such a multitude of requirements results in the simultaneous presence of elements from each concern's implementation, resulting in code tangling.

Isn't that exactly the same as low cohesion? Is there any difference between high tangling and low cohesion, or are that two different words describing the same thing?

Was it helpful?

Solution

Accourding to wikipedia:

The implementation of a concern is tangled if its code is intermixed with code that implements other concerns. The module in which tangling occurs is not cohesive.

Cohesion is decreased if:
- The functionalities embedded in a class, accessed through its methods, have little in common.
- Methods carry out many varied activities, often using coarsely-grained or unrelated sets of data.

So.. when the code is tangled, it would violate SOLID principles such Single Responsibility Principle, Open Closed Priciple etc.

All these principles most often go together and violation of one principle/best practice lead to another.

But tangling doesn't necessarily mean that the code is not cohesive. For example we could have a class called SecurityChecker, which does the authentication of a user log all authentication related activties. Clearly this would be handling multiple concerns which are Authentication and Logging. Therefroe it would be a tangled class. On the other hand both these conerns would be operating on the same set of data which in this case could be user data, times of logon , number of login attempts etc. Therefore cohesion could still be high.

Genrally most of these principles/guidlines/best practices look at the same issue from different perspectives, and the end goal is to manage dependencies between different components/classes etc so that the overall design would be more maintainable , efficient and elegant in the long run.

OTHER TIPS

Very similar yes.

Cohesion is used to indicate the degree to which a class has a single, well-focused purpose.

Therefore if you have a Class with a single well-focused purpose then it would follow that it's not "tangled" by trying to do more than one thing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top