what is difference between adaptables and adapters in aem | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by aanchal-sikka

Adapters define the behavior and structure that Adaptables are converted to.

 

An Adaptable is an object that can be "adapted" into another type.

  • Purpose: It provides a flexible way to convert an object of one type into another type that may be required in a particular context.

  • Example:

    • Common examples of Adaptables in AEM include:
      • SlingHttpServletRequest
      • Resource
      • Page

 

An Adapter is the target type that an Adaptable can be converted into.

  • Purpose: Adapters are the interfaces or classes into which an Adaptable can be transformed.

  • Example:

    • In AEM, common adapters include:
      • ValueMap
      • ResourceResolver
      • Custom classes implementing specific business logic.

 

 

 

3 replies

matija_kovacek
January 8, 2025

Adaptable is source objects that can be adapted, for example Resource.

Adapter is the Target object produced after adaptation, for example, Page.

 

Call .adaptTo(Class) on an Adaptable, where the result of that method is Adapter.

aanchal-sikka
Community Advisor
aanchal-sikkaCommunity AdvisorAccepted solution
Community Advisor
January 8, 2025

Adapters define the behavior and structure that Adaptables are converted to.

 

An Adaptable is an object that can be "adapted" into another type.

  • Purpose: It provides a flexible way to convert an object of one type into another type that may be required in a particular context.

  • Example:

    • Common examples of Adaptables in AEM include:
      • SlingHttpServletRequest
      • Resource
      • Page

 

An Adapter is the target type that an Adaptable can be converted into.

  • Purpose: Adapters are the interfaces or classes into which an Adaptable can be transformed.

  • Example:

    • In AEM, common adapters include:
      • ValueMap
      • ResourceResolver
      • Custom classes implementing specific business logic.

 

 

 

Aanchal Sikka
AmitVishwakarma
Community Advisor
Community Advisor
January 17, 2025

In AEM:

  • Adaptables: Objects that can be converted or adapted to another type (e.g., SlingHttpServletRequest, Resource).
  • Adapters: The mechanism or logic that converts an adaptable to a different type (e.g., adapting a Resource to a Sling Model).

Example:

  • Adaptable: SlingHttpServletRequest
  • Adapter: Logic that adapts the request to a model (like a custom Sling Model).

In short: Adaptables are objects that can be adapted; adapters are the logic that performs the adaptation.