Skip to content

Adapter

A pattern that converts an incompatible existing interface into the interface expected by the current system.

  • When aligning a legacy or external SDK with the project’s standard API.
  • When reusing an existing implementation without modifying it.
  • Target
  • Adaptee
  • Adapter

The code below is a simplified Unity example based on the scenario described above.

public interface IAdsService
{
void ShowRewardedAd(string placementId);
}
public sealed class LegacyAdsSdk
{
public void ShowRewardVideo(string zoneId) { }
}
public sealed class LegacyAdsServiceAdapter : IAdsService
{
private readonly LegacyAdsSdk legacyAdsSdk = new();
public void ShowRewardedAd(string placementId)
{
legacyAdsSdk.ShowRewardVideo(placementId);
}
}
  • It clarifies module boundaries and reduces coupling.
  • Features can be extended or integrated without modifying existing code.
  • If wrapper layers become too deep, debugging gets harder.
  • Interfaces should stay small so responsibility boundaries do not blur.

This shows the flow where an existing interface is converted into the target interface for reuse.

Adapter Flow