Three Concepts you need to know as Senior Software Engineer
Tags: programming, architecture, webdev
Published: 2023-04-19 17:16:07

As a software engineer, you have likely amassed a great deal of technical knowledge and experience in your field. However, there are certain key concepts that are worth knowing. In this article, we will discuss three concepts that every experienced engineer should be familiar with in order to stay ahead of the game.

## Cohesion
In programming, cohesion refers to the degree to which the elements of a module or a software component work together to achieve a single, well-defined purpose or function. In other words, it's a measure of how closely related the parts of a module are to each other.

![Coupling and cohesion (en.wikipedia.org)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/odj8vqcm3fic7u778dvd.png)

**High cohesion** means that the elements within a module are **highly related** and work together closely to achieve a specific task or function. **Low cohesion**, on the other hand, means that the elements within a module are **loosely related** and may not work together efficiently to achieve a specific purpose.
High cohesion is generally considered desirable because it leads to more maintainable and reusable code. It makes it easier to understand and modify a module without affecting the rest of the program. On the other hand, low cohesion can lead to code that is difficult to understand, modify, and maintain, which can result in bugs, errors, and inefficiencies.
Sound great but how to achieve high cohesion and low coupling?

- Single Responsibility Principle (**SRP**): Each class or module should have only one responsibility.
- Interface Segregation Principle (**ISP**): Interfaces should be designed to be as small as possible, with only the methods that are necessary for the implementation of the interface.
- Dependency Inversion Principle (**DIP**): High-level modules should not depend on low-level modules, but both should depend on abstractions.

## Cognitive Complexity

Cognitive complexity is a measure of the difficulty of understanding and reasoning about a piece of code. It takes into account the number of **distinct paths through the code**, **the nesting depth of control structures**, and the number of **logical operators** and **operands**.


![Example of high cognitive complexity](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e2vgkaw5wqu63nihjk8m.png)

A higher cognitive complexity indicates that the code is more difficult to understand and reason about, which can lead to more bugs, slower development time, and more difficult maintenance.
Code with a low cognitive complexity, on the other hand, is easier to read and understand, which can lead to more efficient development and maintenance.
To make code less complex and easy to read apply Clean Code practice, you can find them for every programming languages, [here](https://github.com/ryanmcdermott/clean-code-javascript) for Javascript.

## Design Patterns
Design patterns are **reusable solutions** to commonly **occurring problems** in software design. They are general solutions that can be applied to different situations in software development, making the design and development process more efficient and effective.


![Adapter - structural design pattern (refactoring.guru)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yxmbf4k71ds5x5qngcbd.png)

Design patterns provide a common vocabulary and a set of best practices for software designers and developers. They help to ensure that software is **maintainable**, **flexible**, and **extensible**, and that it meets the needs of its users.
Design patterns can be used in a variety of programming languages and environments, including object-oriented programming, functional programming, and web development. They are widely used in software development and are an important tool for creating high-quality, maintainable, and reusable software.
If you want to learn more about design patterns I highly recommend checking out [Refactoring Guru](https://refactoring.guru/design-patterns), they provide great examples and graphics that help you understand it quicker.