Adapter — wraps the external API, translates its shape into your domain shape.

java

@Component
public class WeatherApiAdapter {
private final RestClient restClient;
public WeatherApiAdapter(RestClient restClient) {
this.restClient = restClient;
}
public WeatherInfo getWeather(String city) {
ExternalWeatherResponse raw = restClient.get()
.uri("/weather?city={city}", city)
.retrieve()
.body(ExternalWeatherResponse.class);
return new WeatherInfo(raw.temp_c(), raw.condition().text());
}
}

Service — contains business logic, uses the adapter, doesn’t know about HTTP.

java

@Service
public class WeatherService {
private final WeatherApiAdapter weatherApiAdapter;
public WeatherService(WeatherApiAdapter weatherApiAdapter) {
this.weatherApiAdapter = weatherApiAdapter;
}
public String getFriendlyForecast(String city) {
WeatherInfo info = weatherApiAdapter.getWeather(city);
return info.temp() > 25 ? "It's hot in " + city : "It's mild in " + city;
}
}

Facade — combines multiple services/adapters behind one simple entry point.

java

@Component
public class TripPlannerFacade {
private final WeatherService weatherService;
private final FlightService flightService;
private final HotelService hotelService;
public TripPlannerFacade(WeatherService weatherService,
FlightService flightService,
HotelService hotelService) {
this.weatherService = weatherService;
this.flightService = flightService;
this.hotelService = hotelService;
}
public TripPlan planTrip(String city) {
return new TripPlan(
weatherService.getFriendlyForecast(city),
flightService.findFlights(city),
hotelService.findHotels(city)
);
}
}

In one line:

  • Adapter → translates an external API into your domain model.
  • Service → business logic built on top of adapters.
  • Facade → a single simplified entry point over multiple services.

Hinterlasse einen Kommentar

I’m Iman

Mein Name ist Iman Dabbaghi. Ich arbeite als Senior Software Engineer in der Schweiz. Außerdem interessiere ich mich sehr für gewaltfreie Kommunikation, Bachata-Tanz und Musik sowie fürs die Persönlichkeitsentwicklung.

Ich habe einen Masterabschluss in Informatik von der Universität Freiburg in Deutschland, bin Spring/Java Certified Professional (OCP), Certified Professional for Software Architecture (CPSA-F) und ein lebenslanger Lernender 🎓.

EN:

My name is Iman Dabbaghi. I work as a Senior Software Engineer in Switzerland. I am also very interessted in nonviolent communication, Bachata dance and music and also for personal development.

I hold a masters degree in computer science from the university of Freiburg in Germany, am a Spring / Java Certified Professional (OCP), Certified Software Architecture (CPSA-F) and Life Long Learner🎓

Let’s connect