> 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 plain words
> Converter pattern makes it easy to map instances of one class into instances of another class.
**Programmatic Example**
We need a generic solution for the mapping problem. To achieve this, let's introduce a generic converter.
```java
public class Converter<T,U> {
private final Function<T,U> fromDto;
private final Function<U,T> fromEntity;
public Converter(final Function<T,U> fromDto, final Function<U,T> fromEntity) {
this.fromDto = fromDto;
this.fromEntity = fromEntity;
}
public final U convertFromDto(final T dto) {
return fromDto.apply(dto);
}
public final T convertFromEntity(final U entity) {
return fromEntity.apply(entity);
}
public final List<U> createFromDtos(final Collection<T> dtos) {