Is it correct to say that encapsulation aims at cohesion? Why?

Asked

Viewed 454 times

8

Based on the statement below, follow my question:

Cohesion and Coupling are very software engineering principles used. When we want to have a mature and sustainable architecture, we must take these two principles into account, for each of them has a specific purpose that aims to improve the design of the software. What it turns out that many people don’t know the difference between them and end up failing to obtain the benefits that put them into practice when designing the architecture of software.

Source: Understanding Cohesion and Coupling - Devmedia

When I’m in the software architecture phase, based on best practices, when I can build a cohesive class with low coupling, I can say that the encapsulamento aims at the coesão?

1 answer

7


Yes, encapsulation is a technique for achieving cohesion, though not the only one. And encapsulation also has its own goals.

Obviously the attempt to carry the encapsulation to iron and fire can harm cohesion. Cohesion is to get the balance. It is common to see the attempt to give more encapsulation and consequently end up increasing the coupling, lowering the cohesion.

Certainly exposing details that do not matter externally goes against encapsulation and makes the component less cohesive. And putting details that don’t concern the object inside it is encapsulating and worsening cohesion.

What are the concepts of cohesion and coupling?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.