docs: Content SEO updates (#2990)

* update yaml frontmatter format

* update abstract document

* update abstract factory

* use the new pattern template

* acyclic visitor seo

* adapter seo

* ambassador seo

* acl seo

* aaa seo

* async method invocation seo

* balking seo

* bridge seo

* builder seo

* business delegate and bytecode seo

* caching seo

* callback seo

* chain seo

* update headings

* circuit breaker seo

* client session + collecting parameter seo

* collection pipeline seo

* combinator SEO

* command seo

* cqrs seo

* commander seo

* component seo

* composite seo

* composite entity seo

* composite view seo

* context object seo

* converter seo

* crtp seo

* currying seo

* dao seo

* data bus seo

* data locality seo

* data mapper seo

* dto seo

* decorator seo

* delegation seo

* di seo

* dirty flag seo

* domain model seo

* double buffer seo

* double checked locking seo

* double dispatch seo

* dynamic proxy seo

* event aggregator seo

* event-based asynchronous seo

* eda seo

* event queue seo

* event sourcing seo

* execute around seo

* extension objects seo

* facade seo

* factory seo

* factory kit seo

* factory method seo

* fanout/fanin seo

* feature toggle seo

* filterer seo

* fluent interface seo

* flux seo

* flyweight seo

* front controller seo

* function composition seo

* game loop seo

* gateway seo

* guarded suspension seo

* half-sync/half-async seo

* health check seo

* hexagonal seo

* identity map seo

* intercepting filter seo

* interpreter seo

* iterator seo

* layers seo

* lazy loading seo

* leader election seo

* leader/followers seo

* lockable object seo

* rename and add seo for marker interface

* master-worker seo

* mediator seo

* memento seo

* metadata mapping seo

* microservice aggregator seo

* api gw seo

* microservices log aggregration seo

* mvc seo

* mvi seo

* mvp seo

* mvvm seo

* monad seo

* monitor seo

* monostate seo

* multiton seo

* mute idiom seo

* naked objects & notification seo

* null object seo

* object mother seo

* object pool seo

* observer seo

* optimistic locking seo

* page controller seo

* page object seo

* parameter object seo

* partial response seo

* pipeline seo

* poison pill seo

* presentation model seo

* private class data seo

* producer-consumer seo

* promise seo

* property seo

* prototype seo

* proxy seo

* queue-based load leveling seo

* reactor seo

* registry seo

* repository seo

* RAII seo

* retry seo

* role object seo

* saga seo

* separated interface seo

* serialized entity seo

* serialized lob seo

* servant seo

* server session seo

* service layer seo

* service locator seo

* service to worker seo

* sharding seo

* single table inheritance seo

* singleton seo

* spatial partition seo

* special case seo

* specification seo

* state seo

* step builder seo

* strangler seo

* strategy seo

* subclass sandbox seo

* table module seo

* template method seo

* throttling seo

* tolerant reader seo

* trampoline seo

* transaction script seo

* twin seo

* type object seo

* unit of work seo

* update method seo

* value object seo

* version number seo

* virtual proxy seo

* visitor seo

* seo enhancements

* seo improvements

* SEO enhancements

* SEO improvements

* SEO additions

* SEO improvements

* more SEO improvements

* rename hexagonal + SEO improvements

* SEO improvements

* more SEO stuff

* SEO improvements

* SEO optimizations

* SEO enhancements

* enchance SEO

* improve SEO

* SEO improvements

* update headers
This commit is contained in:
Ilkka Seppälä
2024-06-08 19:54:44 +03:00
committed by GitHub
parent cb946c0cdc
commit 6cd2d0353a
219 changed files with 3308 additions and 2819 deletions
+25 -23
View File
@@ -1,14 +1,16 @@
---
title: Converter
title: "Converter Pattern in Java: Streamlining Data Conversion Across Layers"
shortTitle: Converter
description: "Discover the benefits and implementation of the Converter Pattern in Java. Learn how to achieve seamless bidirectional conversion between different data formats, promoting clean code and flexibility in your applications."
category: Structural
language: en
tag:
- Compatibility
- Data transformation
- Decoupling
- Interface
- Object mapping
- Wrapping
- Compatibility
- Data transformation
- Decoupling
- Interface
- Object mapping
- Wrapping
---
## Also known as
@@ -16,25 +18,25 @@ tag:
* Mapper
* Translator
## Intent
## Intent of Converter Design Pattern
The purpose of the Converter pattern is to provide a generic, common way of bidirectional conversion between corresponding types, allowing a clean implementation in which the types do not need to be aware of each other. Moreover, the Converter pattern introduces bidirectional collection mapping, reducing a boilerplate code to minimum.
The purpose of the Converter Pattern is to provide a generic, systematic way of bidirectional conversion between corresponding data types. This allows for a clean, decoupled implementation where types are unaware of each other. Additionally, the Converter pattern supports bidirectional collection mapping, minimizing boilerplate code.
## Explanation
## Detailed Explanation of Converter Pattern with Real-World Examples
Real-world example
> In a real-world scenario, consider a scenario where a library system needs to interact with a third-party book database. The library system uses its own internal book format, while the third-party database provides book information in a different format. To facilitate communication between the two systems, a Converter design pattern can be employed. This pattern will define a converter class that transforms the third-party book data format into the library's internal book format and vice versa. This ensures that the library system can seamlessly integrate with the third-party database without altering its own internal structure or the third-party system's format.
> In a real-world scenario, consider a library system that interacts with a third-party book database. The library uses an internal book format, while the third-party database uses a different format. By employing the Converter Pattern, a converter class can transform the third-party book data into the library's format and vice versa. This ensures seamless integration without altering the internal structures of either system.
In plain words
> Converter pattern makes it easy to map instances of one class into instances of another class.
> The Converter Pattern simplifies mapping instances of one class to instances of another class, ensuring consistent and clean data transformation.
**Programmatic Example**
## Programmatic Example of Converter Pattern in Java
In real world applications it is often the case that database layer consists of entities that need to be mapped into DTOs for use on the business logic layer. Similar mapping is done for potentially huge amount of classes, and we need a generic way to achieve this.
In applications, it's common for the database layer to have entities that need mapping to DTOs (Data Transfer Objects) for business logic. This mapping often involves many classes, necessitating a generic solution.
We need a generic solution for the mapping problem. To achieve this, let's introduce a generic `Converter`.
We introduce a generic `Converter` class:
```java
public class Converter<T, U> {
@@ -65,7 +67,7 @@ public class Converter<T, U> {
}
```
The specialized converters inherit from this base class as follows.
Specialized converters inherit from this base class:
```java
public class UserConverter extends Converter<UserDto, User> {
@@ -84,7 +86,7 @@ public class UserConverter extends Converter<UserDto, User> {
}
```
Now mapping between `User` and `UserDto` becomes trivial.
Mapping between `User` and `UserDto` becomes straightforward:
```java
public static void main(String[] args) {
@@ -122,7 +124,7 @@ Program output:
08:28:27.037 [main] INFO com.iluwatar.converter.App -- UserDto[firstName=Kate, lastName=Smith, active=true, email=if0243]
```
## Applicability
## When to Use the Converter Pattern in Java
Use the Converter Pattern in the following situations:
@@ -131,18 +133,18 @@ Use the Converter Pattern in the following situations:
* For legacy systems integration where data models differ significantly from newer systems.
* When aiming to encapsulate conversion logic to promote single responsibility and cleaner code.
## Tutorials
## Converter Pattern Java Tutorials
* [Converter Pattern in Java 8 (Boldare)](http://www.xsolve.pl/blog/converter-pattern-in-java-8/)
## Known Uses
## Real-World Applications of Converter Pattern in Java
* Data Transfer Objects (DTOs) conversions in multi-layered applications.
* Adapting third-party data structures or API responses to internal models.
* ORM (Object-Relational Mapping) frameworks for mapping between database records and domain objects.
* Microservices architecture for data exchange between different services.
## Consequences
## Benefits and Trade-offs of Converter Pattern
Benefits:
@@ -156,13 +158,13 @@ Trade-offs:
* Overhead: Introducing converters can add complexity and potential performance overhead, especially in systems with numerous data formats.
* Duplication: There's a risk of duplicating model definitions if not carefully managed, leading to increased maintenance.
## Related Patterns
## Related Java Design Patterns
* [Adapter](https://java-design-patterns.com/patterns/adapter/): Similar in intent to adapting interfaces, but Converter focuses on data models.
* [Facade](https://java-design-patterns.com/patterns/facade/): Provides a simplified interface to a complex system, which might involve data conversion.
* [Strategy](https://java-design-patterns.com/patterns/strategy/): Converters can use different strategies for conversion, especially when multiple formats are involved.
## Credits
## References and Credits
* [Design Patterns: Elements of Reusable Object-Oriented Software](https://amzn.to/3w0pvKI)
* [Effective Java](https://amzn.to/4cGk2Jz)