You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

1 Días
0 Hrs
42 Min
13 Seg

Integraciones y patrón Adapter

21/24
Resources

How to implement integrations in applications with clean architecture?

Modern applications require sophisticated integrations to interact with other systems and services. Whether it is sending notifications, managing files, or communicating with other services, an effective implementation is crucial. Clean architecture offers an orderly approach to these integrations, allowing the cohesion of the system to be maintained without compromising its structure.

What are common types of integrations?

  1. Sending messages: Applications send emails, text messages, push notifications, among others. These notifications can alert users to important events, such as the availability of a new report or changes to their account.

  2. Reading and writing files: Saving files to disk or to the cloud is part of the integrations. Using storage in services such as Amazon S3 replaces local storage, keeping the business logic independent of the technology used.

  3. Communication with other services: This includes the use of REST APIs, messaging queues or remote procedure invocation (RPC). These integrations allow services to exchange data efficiently.

What is a design pattern and how does it help?

Design patterns are proven solutions to common problems in software development. Among the 23 original patterns, the Adapter Pattern is essential for integrating incompatible interfaces.

The Adapter Pattern consists of:

  • Converting an interface into another compatible interface.
  • Acting as an intermediary between the client and the adaptee, which is the particular implementation we want to use.

How does a code example help to understand the integrations?

In the Spring Boot implementation for airlines, we create a WeatherAdapter interface. This sits in the domain and abstracts the details of how the weather information is obtained.

For example:

 {public interface WeatherAdapter { Weather getWeather(String location);}

This adapter interacts with well-known services such as Open Weather Map to obtain weather forecasts. It is important to respect the interface while adapting details such as the API URL or the access key. This abstraction ensures that the domain is not affected by the way the information is obtained.

What are the recommendations for the use of design patterns?

When implementing software integrations:

  • Use the right pattern for each problem.
  • Keep business logic separate from integrations.
  • Consider using dependency injection to handle specific implementations.

What additional resources are available?

To go deeper, we recommend exploring the design patterns course that provides more detail on the Adapter Pattern and other patterns. Learning these tools will expand your skills in designing clean and efficient software.

Learning how to effectively integrate different services will strengthen your applications, preparing them to respond to today's technological demands. As you progress, try implementing the Adapter Pattern in your projects and share your experiences.

Contributions 5

Questions 4

Sort by:

Want to see more contributions, questions and answers from the community?

Integraciones y patrón Adapter

Ejemplos comunes

  1. Envío de mensajes.
    1. Correos electrónicos.
    2. Mensajes de texto.
    3. Notificaciones push (web o móvil).
    4. Mensajes de chat (WhatsApp o Telegram).
  2. Escritura y lectura de archivos.
    1. Disco.
    2. Almacenamiento de objetos.
    3. Servidor FTP.
  3. Comunicación con otros servicios.
    1. Colas de mensajería.
    2. REST.
    3. Llamado de procedimientos remotos (RPC).

Patrones de diseño

Son soluciones recurrentes a un problema de diseño.

Patrón Adapter

Convierte la interfaz de una clase en otra interfaz que el cliente espera. Permite que objetos con interfaces incompatibles trabajen juntos.

Ejemplo:

Se tiene una clase Client que utiliza la interfaz GestorArchivo, la cual tiene la firma del siguiente método:

  • guardar(ruta, contenido)

Se crea una nueva interfaz denominada AdaptadorS3 la cual tiene la firma del mismo método:

  • guardar(ruta, contenido)

Se crea una clase S3 que implementa la intefaz AdaptadorS3 con la implementación del método:

  • put()

Dicho método contiene la implementación propia para guardar o actualizar archivos en S3.

De esta forma cuando el dominio utilice la interfaz GestorArchivo estará accediendo a una interfaz genérica sin preocuparse por la implementación de la misma, que es básicamente lo que se busca en una arquitectura limpia.

recientemente he realizado integraciones con Payu y la plataforma de pse, no ha sido tan similares a estas. pero después de este curso todo va a ser muy distinto

Dentro de la experiencia que tengo, creo que me he acercado a este patrón es de la siguiente manera: Tenemos componentes en nube que soportan REST, pero tenemos que hacer uso de servicios en Tierra que emplean SOAP, entonces se han construido componentes que se encargan de recibi n ua petición REST, construyen la peticion soap, se obtiene la respuesta, nos la devuelve al negocio y así trabajamos en lo que necesitamos
Estaria bueno ver como se integra este Adapter dentro del codigo, por que no tiene ningun uso en los archivos del repositorio